高中生程式解題系統:提款卡密碼
題目連結 http://zerojudge.tw/ShowProblem?problemid=a065。
此題用字串與字元的ASCII編碼來處理即可。
程式碼:
此題用字串與字元的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;
}
若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。
留言