#include #include #include using namespace std; int calculate(char *); int main(){ cout<<"請輸入字串 : "; char buff[1000]; scanf("%s", buff); int diff=calculate(buff); printf("%d\n", diff); } int calculate(char *buff){ int odd=0, even=0; for (int i=0;buff[i]!='\0';i++){ if(i%2==0)even+=buff[i]-48; else odd+=buff[i]-48; } return abs(odd-even); }