[問題] 高中程式解題的C290
https://zerojudge.tw/ShowProblem?problemid=c290
題目如上
找到參考解答 請問 A=A+s[i]-'0'; 中 -'0' 的意義是什麼?
#include <iostream>
using namespace std;
int main(){
string s;
int A,B;
while(cin >> s){
A=0,B=0;
for(int i=0;i<s.length();i++){
if (i%2){
A=A+s[i]-'0';
}else{
B=B+s[i]-'0';
}
}
if (A>B) cout << A-B << endl;
else cout << B-A << endl;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.203.74.58
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1537277311.A.3C7.html
推
09/18 21:44,
7年前
, 1F
09/18 21:44, 1F
→
09/18 21:45,
7年前
, 2F
09/18 21:45, 2F
→
09/18 21:45,
7年前
, 3F
09/18 21:45, 3F
推
09/18 23:59,
7年前
, 4F
09/18 23:59, 4F
→
09/19 00:00,
7年前
, 5F
09/19 00:00, 5F
→
09/19 00:08,
7年前
, 6F
09/19 00:08, 6F