#include <iostream> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); string str; while(cin >> str){ for (int i=0; i<str.size()-1; i++){ cout << abs(str[i]-str[i+1]); } cout <<endl; } }
你只加速了一半。
把endl改成'\n'後, AC (12ms, 348KB)
如果輸入輸出改用fgets和putchar還可以更快
AC (2ms, 40KB)