http://zerojudge.tw/ShowProblem?problemid=d086
魔鬼測資:0123→Fail,而不是結束程式
所以檢查字串時還要確認是單純的"0"(結束程式),還是一個"0"開頭的字串(輸出 Fail)
魔鬼測資:0123→Fail,而不是結束程式
所以檢查字串時還要確認是單純的"0"(結束程式),還是一個"0"開頭的字串(輸出 Fail)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /**********************************************************************************/ /* Problem: d086 "態度之重要的證明" from 成功電研20th~21st C++ ~最後的競賽~ */ /* Language: CPP (650 Bytes) */ /* Result: AC(4ms, 464KB) judge by this@ZeroJudge */ /* Author: jrsh0906 at 2013-07-11 15:58:44 */ /**********************************************************************************/ /* Author: Hsu Shih Po Date: 11/07/13 15:41 Description: d086: 態度之重要的證明 */ #include <iostream> #include <cstdlib> using namespace std; int main() { string proof; while(cin>>proof) { if(proof[0]=='0' && proof[1]=='\0')break; int sum = 0; for(int i = 0;i < proof.length();i++) { if(proof[i]>='A' && proof[i]<='Z') sum += proof[i] - 64; else if(proof[i]>='a' && proof[i]<='z') sum += proof[i] - 96; else { sum = -1; break; } } if(sum != -1)cout<<sum<<endl; else cout<<"Fail"<<endl; } return 0; } /* A:65 a:97 Z:90 z:122 */ |
沒有留言:
張貼留言