1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<math.h> 5 using namespace std; 6 int main() 7 { 8 int n,i,j; 9 while(scanf("%d",&n)!=EOF) 10 { 11 int a=1,b=2,numa=0,numb=0,aa,bb; 12 for(i=0;i<n;i++) 13 { 14 scanf("%d%d",&aa,&bb); 15 if(aa==a) 16 { 17 numa++; 18 a=bb; 19 } 20 if(aa==b) 21 { 22 numb++; 23 b=bb; 24 } 25 } 26 if(numa==numb) 27 printf("You are my brother "); 28 else if(numa<numb) 29 printf("You are my younger "); 30 else 31 printf("You are my elder "); 32 } 33 return 0; 34 }
这题好水 啊 不说明白题意
我的考虑太片面 所以下面粘上全面代码
1 #include "stdio.h" 2 typedef struct stu 3 { 4 int a; 5 int b; 6 }S; 7 int main() 8 { 9 int i,j,n,ansa,ansb,amounta,amountb; 10 S old[1005]; 11 while(scanf("%d",&n)==1) 12 { 13 for(i=0;i<n;i++) 14 { 15 scanf("%d%d",&old[i].a,&old[i].b); 16 if(old[i].a==1)//到little A; 17 ansa=1; 18 if(old[i].a==2)//到little B; 19 ansb=2; 20 } 21 amounta=1; 22 i=0; 23 while(i<n)//计算A是家族中的第几代; 24 { 25 for(i=0;i<n;i++) 26 { 27 if(old[i].a==ansa) 28 { 29 amounta++; 30 ansa=old[i].b; 31 break; 32 } 33 } 34 } 35 amountb=1; 36 j=0; 37 while(j<n)//计算B是家族中的第几代; 38 { 39 for(j=0;j<n;j++) 40 { 41 if(old[j].a==ansb) 42 { 43 amountb++; 44 ansb=old[j].b; 45 } 46 } 47 } 48 if(amounta>amountb) 49 printf("You are my elder "); 50 else if(amounta<amountb) 51 printf("You are my younger "); 52 else 53 printf("You are my brother "); 54 } 55 return 0; 56 }