/
584.cpp
118 lines (109 loc) · 1.91 KB
/
584.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//Steven Kester Yuwono - UVa 584 - Bowling
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int getIntValue(char tempChar){
if ((tempChar>='0')&&(tempChar<='9')){
return tempChar-'0';
}
return -1;
}
void calcScore(char score[], int scoreInt[], int round[],int total){
int number=0;
int roundNum=0;
int tempScore=0;
for(int i=0;i<total;i++){
tempScore=getIntValue(score[i]);
if(number==0){
roundNum++;
}
if(tempScore>=0){
scoreInt[i]=tempScore;
if(number==0){
number++;
}
else{
number=0;
}
round[i]=roundNum;
}
else{
number=0;
round[i]=roundNum;
if(score[i]=='/'){
scoreInt[i]=10-getIntValue(score[i-1]);
}
else if(score[i]=='X'){
scoreInt[i]=10;
}
}
}
}
int main(){
int ans=0;
char score[30];
int scoreInt[30];
int round[30];
for(int i=0;i<30;i++){
score[i]='0';
scoreInt[i]=0;
round[i]=0;
}
string temp;
int tempScore;
getline(cin,temp);
while(temp!="Game Over"){
istringstream istream(temp);
int i=0;
while(istream>>score[i++]){
}
calcScore(score, scoreInt,round, i);
for(int j=0;j<i;j++){
tempScore=getIntValue(score[j]);
//cout << tempScore << endl;
if(tempScore>=0){
ans+=tempScore;
}
else{
if(score[j]=='/'){
tempScore=scoreInt[j];
if(round[j]<10){
tempScore+=scoreInt[j+1];
}
ans+=tempScore;
}
else if(score[j]=='X'){
tempScore=scoreInt[j];
if(round[j]<10){
tempScore+=scoreInt[j+1];
tempScore+=scoreInt[j+2];
}
ans+=tempScore;
}
}
}
cout << ans << endl;
/*
for(int i=0;i<30;i++){
cout << score[i]<< " ";
}
cout <<endl;
for(int i=0;i<30;i++){
cout << scoreInt[i] << " ";
}
cout <<endl;
for(int i=0;i<30;i++){
cout << round[i] << " ";
}
*/
for(int i=0;i<30;i++){
score[i]='0';
scoreInt[i]=0;
round[i]=0;
}
ans=0;
getline(cin,temp);
}
return 0;
}