标签:判断 cstring bsp content ++ while span 存储 比较
5
1 3
2 4
3 5
4 6
5 6
6
1 3
2 4
3 5
4 6
5 7
6 7
思路:
这道题目的数据是a的b关系。(多组数据,这是个坑!)
纯模拟。
再按照判断即可。
如果小宇是小明的晚辈,则输出“You are my younger”,
如果小宇是小明的长辈,则输出“You are my elder”,
如果是同辈则输出“You are my brother”。
开两个数组存储a与b的状态比较。
也可以用链表向上查找。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int a[105];
int main(){
int n;
while(cin>>n){
for(int i=1;i<=100;i++)
a[i]=i;
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
a[x]=y;
}
int s1=0;
for(int i=1;i!=a[i];i=a[i])s1++;
int s2=0;
for(int i=2;i!=a[i];i=a[i])s2++;
if(s1>s2)cout<<"You are my elder"<<endl;
else if(s1==s2)cout<<"You are my brother"<<endl;
else cout<<"You are my younger"<<endl;
}
return 0;
}
OVER!
标签:判断 cstring bsp content ++ while span 存储 比较
原文地址:https://www.cnblogs.com/wangshengjun/p/10628661.html