#UVa:1585-Score

灆洢 2015-07-22 09:21:15

按照題目要求去處理字串去將每個連續的O的分數累加起來即可得解。

P.S. 這題我用一般會用的while(scanf() != EOF)以及getline()會得到WA,不知道測資還塞了些什麼東西…..

C++(0.000)

/*******************************************************/
/* UVa 1585 Score                                      */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2015/07/22                                 */
/*******************************************************/
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main(){
  int T;
  scanf("%d", &T);
  for( int caseCount = 0 ; caseCount < T ; ++caseCount ){
    string input;
    cin >> input;

    int score = 0, add = 1;
    for( int i = 0 ; i < input.length() ; ++i ){
      if( input[i] == 'O' ){
        score += add;
        ++add;
      }
      else {
        add = 1;
      }
    }

    printf("%d\n", score);
  }
  return 0;
}

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料