zoukankan      html  css  js  c++  java
  • 《算法竞赛入门经典》习题31 得分(Score,ACM、ICPC Seoul 2005,UVa1585)

    原题及翻译

    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 <stdio.h>
    #include <string.h>
    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居然也有这么简单的题。

  • 相关阅读:
    SIMULINK动态仿真集成环境
    自带计算器
    零知识证明
    2012年软件大赛校内选拔赛
    使用VC2005 Express版时找不到msvcr80d.dll文件
    DirectX 90 3D SetRenderState 设置渲染状态
    ofstream和ifstream详细用法
    IncrediBuild 进行联合编译
    环形缓冲区,魔戒lordrings,boost的circular_buffer
    vector中resize和reserve接口的异同
  • 原文地址:https://www.cnblogs.com/AlexKing007/p/12339521.html
Copyright © 2011-2022 走看看