1071 小賭怡情 (15 分)

  • 2019 年 10 月 30 日
  • 筆記

【我的代碼】

// 1071 小賭怡情 (15 分)  #include <iostream>  using namespace std;  int main(){        int n1, b, t, n2, total, N;      cin>>total>>N;      for(int i = 0; i < N; i++){          cin>>n1>>b>>t>>n2;          if(total < t){              cout<<"Not enough tokens.  Total = "<<total<<"."<<endl;              continue;          }          if(n1 > n2 && !b){              total += t;              cout<<"Win "<<t<<"!  Total = "<< total<<"."<<endl;          }          else if(n1 < n2 && b){              total += t;              cout<<"Win "<<t<<"!  Total = "<< total <<"."<< endl;          }          else{              total -= t;              cout<<"Lose "<<t<<".  Total = "<< total<<"."<< endl;              if(total == 0){                  cout<<"Game Over.";                  return 0;              }          }      }      return 0;  }  

【思路】

  1. 邊輸入邊處理,根據total的情況討論好就行了。