[問題] 高中程式解題的C290

看板C_and_CPP作者 (....)時間7年前 (2018/09/18 21:28), 編輯推噓2(204)
留言6則, 4人參與, 7年前最新討論串1/1
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
ascii code to 整數: 0x30 ~ 0x39 對應 0 ~ 9
09/18 21:44, 1F

09/18 21:45, 7年前 , 2F
我好像有點理解錯問題……
09/18 21:45, 2F

09/18 21:45, 7年前 , 3F
回錯XD
09/18 21:45, 3F

09/18 23:59, 7年前 , 4F
一樓的意思是說,利用數字的ASCII碼做運算
09/18 23:59, 4F

09/19 00:00, 7年前 , 5F
利用s[i]的ASCII碼減掉0的ASCII碼可以得到s[i]是什麼數字
09/19 00:00, 5F

09/19 00:08, 7年前 , 6F
懂了~
09/19 00:08, 6F
文章代碼(AID): #1ReFr_F7 (C_and_CPP)