結果
問題 |
No.656 ゴルフ
|
ユーザー |
|
提出日時 | 2018-10-23 11:53:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,138 bytes |
コンパイル時間 | 726 ms |
コンパイル使用メモリ | 54,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-19 04:06:11 |
合計ジャッジ時間 | 1,022 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 |
ソースコード
/*A君の仕事はゴルフのスコア表の計算です。 ゴルフのスコアはボールを1回打つごとに1加算されます。 例えば、あるホールで4打打ったとすればスコア表に4と記載しスコアは4です。 例外として、10打以上打った場合にはスコア表に0と記載してスコアは10となります。 A君は9ホールぶんのスコア表を渡されるのでスコアの合計を計算しましょう。 なお、ゴルフというスポーツの性質上、0打でホールを終了することはありえません! */ #include <cstdlib> #include <iostream> #include <string> #include <typeinfo> using namespace std; int main(){ string score; int scores[9]; int total=0; cin>>score; for (int i = 0; i < 9; ++i) { if(score[i]=='0'){ scores[i]=10; }else{ scores[i]=score[i]-'0'; //ポイント!!!!!! } } for (int i = 0; i < 9; ++i) { total+=scores[i]; } cout<<total<<endl; } /*今回のポイントは文字→数字の変換で「文字-'0'」のテクニックを使うところ ASCIIコードを考えれば理解は難しくない*/