Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct Player//玩家的結構
- {
- char name;//名字
- int index;//出牌數
- string card[13];//牌內容
- }player[4];
- int main()
- {
- for(int i = 0 ; i < 4 ; i++)
- {//依序讀入4位玩家資料
- cin >> player[i].name;
- player[i].index = 0;
- for(int j = 0 ; j < 13 ; j++)
- cin >> player[i].card[j];
- }
- int total = 0;//總數字
- int i = 0;
- int add = 1;//出牌方向,1為向下,-1為向上
- while(1)
- {
- char newcard = player[i].card[player[i].index][0];
- if (newcard == 'A')
- {//A為歸零牌
- player[i].index++;
- total = 0;
- if (player[i].index == 13)
- {//該玩家出牌結束
- cout << player[i].name << endl;
- cout << total << endl;
- return 0;
- }
- }
- else if (newcard == '4')
- {//4為迴轉牌
- player[i].index++;
- if (player[i].index == 13)
- {//該玩家出牌結束
- cout << player[i].name << endl;
- cout << total <<endl;
- return 0;
- }
- add *= -1;//轉向
- }
- else if (newcard == '5')
- {//5為指定牌(出此牌不用累加數字,換下一位出牌者出牌)
- player[i].index++;
- if (player[i].index == 13)
- {//該玩家出牌結束
- cout << player[i].name << endl;
- cout << total << endl;
- return 0;
- }
- }
- else if (newcard == '1')
- {//10為加減10牌(將累加數字加10,但如累加數字加10會超過99則減10)
- player[i].index++;
- if (total <= 89)
- total += 10;
- else total -= 10;
- if (player[i].index == 13)
- {//該玩家出牌結束
- cout << player[i].name << endl;
- cout << total << endl;
- return 0;
- }
- }
- else if (newcard=='J')
- {//J為跳過牌
- player[i].index++;
- if (player[i].index == 13)
- {//該玩家出牌結束
- cout << player[i].name << endl;
- cout << total <<endl;
- return 0;
- }
- }
- else if (newcard=='Q')
- {//Q為加減20牌(將累加數字加20,但如累加數字加20會超過99則減20)
- player[i].index++;
- if (total <= 79)
- total += 20;
- else total -= 20;
- if (player[i].index == 13)
- {//該玩家出牌結束
- cout << player[i].name << endl;
- cout << total << endl;
- return 0;
- }
- }
- else if (newcard=='K')
- {//K為99牌(出此牌不管累加數字為何,直接累加到99,當累加數字已為99時可以再出K,累加數字保持99)
- player[i].index++;
- total = 99;
- if (player[i].index == 13)
- {//該玩家出牌結束
- cout << player[i].name << endl;
- cout << total << endl;
- return 0;
- }
- }
- else
- {//其他牌
- player[i].index++;
- total += newcard - '0';
- if (total > 99)
- {
- cout << player[i].name << endl;
- cout << 13 - player[i].index << endl;
- return 0;
- }
- }
- i += add; //換下一個玩家
- if (i == -1) i = 3;
- else if (i == 4) i = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement