您当前的位置: 首页 >  算法

《算法竞赛入门经典》习题3-1 得分(Score,ACM、ICPC Seoul 2005,UVa1585)

发布时间:2019-02-08 21:44:16 ,浏览量:0

原题及翻译

There is an objective test result such as “OOXXOXXOOO”. 有一个客观的测试结果,比如“ooxxoxoo”。 An ‘O’ means a correct answer of a problem and an ‘X’ means a wrong answer. “O”表示问题的正确答案,“X”表示错误答案。 The score of each problem of this test is calculated by itself and its just previous consecutive ‘O’s only when the answer is correct. 这个测试中每个问题的分数都是由它自己计算的,只有当答案正确时,它才是前一个连续的“O”。 For example, the score of the 10th problem is 3 that is obtained by itself and its two previous consecutive ‘O’s. 例如,第10个问题的分数是3,这是由它自己及其前两个连续的“o”得到的。 Therefore, the score of “OOXXOXXOOO” is 10 which is calculated by “1+2+0+0+1+0+0+1+2+3”. 因此,“ooxxoxxooo”的得分为10,按“1+2+0+0+1+0+0+1+2+3”计算。 You are to write a program calculating the scores of test results. 你要写一个计算考试成绩的程序。

Input

输入 Your program is to read from standard input. 您的程序将从标准输入中读取。 The input consists of T test cases. 输入由T测试用例组成。 The number of test cases T is given in the first line of the input. 测试用例数t在输入的第一行给出。 Each test case starts with a line containing a string composed by ‘O’ and ‘X’ and the length of the string is more than 0 and less than 80. 每个测试用例以一行开始,该行包含由“o”和“x”组成的字符串,字符串长度大于0小于80。 There is no spaces between ‘O’ and ‘X’. “o”和“x”之间没有空格。

Output

输出 Your program is to write to standard output. 您的程序将写入标准输出。 Print exactly one line for each test case. The line is to contain the score of the test case. 每个测试用例只打印一行。该行包含测试用例的得分。

Sample Input

5 OOXXOXXOOO OOXXOOXXOO OXOXOXOXOXOXOX OOOOOOOOOO OOOOXOOOOXOOOOX

Sample Output

10 9 7 55 30

思路

使用数组把所有的测试用例读入,然后处理。

代码
#include  #include  int main () { int n; scanf("%d",&n); char a[n][80]; int b[n][80],sum[n]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(sum,0,sizeof(sum)); for(int i=0;i<n;i++) { scanf("%s",a[i]); int lena=strlen(a[i]),index=0;; for(int j=0;j<lena;j++) { if(a[i][j]=='X') {b[i][j]=0;index=0;} if(a[i][j]=='O') b[i][j]=++index; sum[i]+=b[i][j]; } printf("%d\n",sum[i]); } return 0; } 
每天磕一道ACM打卡

难以置信的事实,ACM居然也有这么简单的题。

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    109966博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.4338s