結果

問題 No.656 ゴルフ
ユーザー PraiPrai
提出日時 2018-10-23 11:53:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,138 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 51,704 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 06:17:10
合計ジャッジ時間 1,222 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*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コードを考えれば理解は難しくない*/
0