題目連結 http://zerojudge.tw/ShowProblem?problemid=a065。
此題用字串與字元的ASCII編碼來處理即可。
程式碼:
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
 string s = "";
 
 while(cin >> s) 
 {
  char c = s[0];
  
  for(int i = 1; i < s.size(); i++) {
   int code = c - s[i];
   if(code < 0)
    code = -code;
   cout << code;
   c = s[i];
  }
  
  cout << endl;
 }
 return 0;
}
沒有留言:
張貼留言