#UVa:12403-Save Setu

灆洢 2015-12-02 15:08:53

照著題目要求加總donate進來的金額,並在輸入report的時候做輸出。

C++(0.000)

/*******************************************************/
/* UVa 12403 Save Setu                                 */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2015/12/02                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
  int T;
  while( scanf("%d", &T) != EOF ){
    int totalMoney = 0;

    for( int i = 0 ; i < T ; ++i ){
      string cmd;
      cin >> cmd;
      if( cmd == "donate" ){
        int money;
        scanf("%d", &money);
        totalMoney += money;
      }
      else if( cmd == "report" ){
        printf("%d\n", totalMoney);
      }
    }
  }
  return 0;
}

發表迴響

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