看板 C_and_CPP 關於我們 聯絡資訊
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
cutekid: ascii code to 整數: 0x30 ~ 0x39 對應 0 ~ 9 09/18 21:44
Sanvean: 我好像有點理解錯問題…… 09/18 21:45
Sanvean: 回錯XD 09/18 21:45
Ori185: 一樓的意思是說,利用數字的ASCII碼做運算 09/18 23:59
Ori185: 利用s[i]的ASCII碼減掉0的ASCII碼可以得到s[i]是什麼數字 09/19 00:00
tyjh: 懂了~ 09/19 00:08