编程语言
首页 > 编程语言> > 【PAT甲级、C++】1032 Sharing (25分)

【PAT甲级、C++】1032 Sharing (25分)

作者:互联网

我知道这么写暴力法肯定会有问题,但还是尝试了下,果然最后两个测试点不通过

# include <iostream>

using namespace std;

int AddrNow[100010];
char Info[100010];
int AddrNxt[100010];
int N;

int main()
{
    int start1, start2;
    cin >> start1 >> start2 >> N;
    for(int i=0;i<N;++i)
        cin >> AddrNow[i] >> Info[i] >> AddrNxt[i];

    int i, j, cnt = 0;
    for(i=0;i<N;++i){
        cnt = 0;
        for(j=0;j<N;++j)
            if(AddrNxt[j] == AddrNow[i])
                cnt++;
        if(cnt == 2)
            break;
    }
    
    if(cnt == 2)
        cout << AddrNow[i];
    else
        cout << -1;
    
    return 0;
}

标签:Info,25,cnt,Sharing,PAT,int,start1,start2,100010
来源: https://blog.csdn.net/MYMarcoreus/article/details/110672277