Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
各位大牛帮我看一下,问题出在哪?#include<iostream> #include<math.h> #include<algorithm> #include<string> using namespace std; struct people { char father[100]; char child[100]; int bornage; }a[1100]; struct name { char pepname[100]; int age; }b[1100]; bool cmp(const name &n1,const name &n2) { if(n1.age==n2.age) return (strcmp(n1.pepname,n2.pepname)<0); return n1.age>n2.age; } int main() { int k,rel,i,j,n; int cases=1; scanf("%d",&rel); while(rel--) { scanf("%d",&n); k=0; strcpy(b[0].pepname,"Ted"); b[0].age=100; for(i=1;i<=n;i++) { scanf("%s%s%d",a[i].father,a[i].child,&a[i].bornage); if(strcmp(a[i].father,"Ted")==0) { strcpy(b[++k].pepname,a[i].child); b[k].age=100-a[i].bornage; } } printf("DATAAET %d\n",cases++); for(j=1;j<=n;j++) for(i=1;i<=n;i++) { if(strcmp(b[j].pepname,a[i].father)==0) { strcpy(b[++k].pepname,a[i].child); b[k].age=abs(b[j].age-a[i].bornage); } } sort(b+1,b+k+1,cmp); cout<<b[1].pepname<<" "<<b[1].age<<endl; for(i=2;i<=k;i++) if(strcmp(b[i].pepname,b[i-1].pepname)!=0) cout<<b[i].pepname<<" "<<b[i].age<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator