#39999: cpp解


dvbdarcyvolleyball@gmail.com (王森洋)

學校 : 不指定學校
編號 : 266888
來源 : [114.45.197.197]
最後登入時間 :
2024-04-30 22:24:12
a271. 彩色蘿蔔 -- 兔子 | From: [36.229.95.200] | 發表日期 : 2024-04-19 06:05

#include <iostream>
#include <sstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int i, times;
  int x, y, z, w, n, m;
  string line, Line;
  cin >> times;

  for(i = 0; i < times;i++){
    int carrot = 0, poisondamage = 0;

    cin >> x >> y >> z >> w >> n >> m;

    cin.ignore();

    getline(cin,Line);
    stringstream SS(Line);

    if(Line == ""){
      cout << m << "g" << endl; 
      continue;
    }
      while(SS >> carrot){
        SS.clear();
        m -= (poisondamage * n);
        if(m <= 0){
          cout << "bye~Rabbit\n";
          break;
        }    
        
        if(carrot == 0){
          continue;
        }
        else if(carrot == 1){
          m += x;
        }
        else if(carrot == 2){
          m += y;
        }
        else if(carrot == 3){
          m -= z;
        }
        else if(carrot == 4){
          m -= w;
          poisondamage += 1;
        }
        if(m <= 0){
          cout << "bye~Rabbit\n";
          break;
        }
      }
    if(m > 0){
      cout << m << "g\n";
    }
  }
}

cin.ignore()的位置要看清楚,break跟continue的使用時機

 
ZeroJudge Forum