#30093: C++解


andrew3321@gmail.com (yungchun huang)

學校 : 不指定學校
編號 : 126959
來源 : [163.19.102.114]
最後登入時間 :
2024-01-11 13:03:09
h026. 202001_1 猜拳 -- 2020年1月APCS | From: [163.19.102.169] | 發表日期 : 2022-04-28 13:55

#include <iostream>

using namespace std;

int main()
{
    int F,N;
    cin >>F>>N;
    int a[N],b[N];

    b[0]=F;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    b[1]=a[0];
    for(int i=2;i<N;i++)b[i]=a[i-1];

    for(int i=2;i<N;i++){
    if(a[i-2]==a[i-1]&&a[i-1]==0)b[i]=5;
    else if(a[i-2]==a[i-1]&&a[i-1]==2)b[i]=0;
    else if(a[i-2]==a[i-1]&&a[i-1]==5)b[i]=2;
    }

    for(int i=0;i<N;i++){
    if(a[i]==0&&b[i]==5){
            cout << b[i]<<" : Won at round "<< i+1 << endl;
            break;}
    if(a[i]==2&&b[i]==0)
    {
        cout << b[i]<<" : Won at round "<< i+1 << endl;
        break;}
    if(a[i]==5&&b[i]==2)
    {
        cout << b[i]<<" : Won at round "<< i+1 << endl;
        break;}
    if(a[i]==5&&b[i]==0)
    {
        cout << b[i]<<" : Lost at round "<< i+1 << endl;
        break;}
    if(a[i]==0&&b[i]==2)
    {
        cout << b[i]<<" : Lost at round "<< i+1 << endl;
        break;}
    if(a[i]==2&&b[i]==5)
    {
        cout << b[i]<<" : Lost at round "<< i+1 << endl;
        break;}

    cout << b[i] << " ";

    }
    if(b[N-1]==a[N-1]){cout <<": Drew at round "<< N << endl;
        }

    return 0;
}

 
ZeroJudge Forum