UVa-1585 Score (Score), uva-1585score Score
Hello world!
Celebrate the first official blog!
UVa-1585 Score
Question stem: Give a string (length) consisting of O and X, and calculate the score. Each O score is the number of consecutive O Records, and X scores are 0. For example, the OOXXOXXOOO score is 1 + 2 + 0 + 0 + 1 + 0 + 0 + 1 + 2 + 3.
Input Format: read data from standard input. Enter an integer T as the number of test data, and then each row provides a continuous (no space) OX string. The length of each string is greater than 0 and less than 80.
Output Format: Write to standard output. One row and one integer are used as the result.
Example and original questions see https://cn.vjudge.net/problem/uva-1585
Analysis: If you have a question, you can leave it alone. However, we need to emphasize that,The format of the sample may be misunderstood. People think that the answer is written to the standard output only after all the answers are input. In fact, you can output it immediately.
1 // cpp 2 # include <iostream> 3 # include <string> 4 using namespace std; 5 int main () 6 {7 string ox; 8 int N; 9 cin> N; 10 while (N --) 11 {12 unsigned score = 0, o_time = 0; 13 cin> ox; 14 for (char a: ox) // The range of C ++ 11 is for loop 15 {16 if (a = 'X') 17 {18 o_time = 0; // reset the number of O occurrences 19 continue; 20} 21 if (a = 'O') score + = ++ o_time; 22} 23 cout <score <endl; 24} 25 return 0; 26}