UVa-1585 Score (Score), uva-1585score Score

Source: Internet
Author: User

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}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.