# APCS 2017年3月 實作1 - 秘密差 ## 題目敘述 [https://zerojudge.tw/ShowProblem?problemid=c290](https://zerojudge.tw/ShowProblem?problemid=c290) ## 程式碼 ```cpp= #include <bits/stdc++.h> using namespace std; int main(){ string str; cin >> str; int len = str.length(); int odd = 0; int even = 0; for(int i=0; i<len; i++){ if((i+1) % 2 == 1){ odd += str[i] - 48; }else{ even += str[i] - 48; } } cout << abs(odd-even) << endl; } ``` ## 執行結果 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up