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 |
为什么总是RE,大家帮我看看:#include <iostream> #include <fstream> using namespace std; int m,q; struct employee{ char ID[30]; char weidge[30]; char height[30]; } p[30001]; int cmp(const void *a1,const void *a2){ employee s=*(employee *)a1; employee t=*(employee *)a2; return strcmp(t.weidge,s.weidge); } void sch(const char *q){ for(int i=0;i<m;i++){ if(strcmp(p[i].ID,q)==0){ if(i==0){ cout<<0<<" "<<m-1<<endl; //如果是第一个节点就是root }else{ int pre=i-1; //分别向前查找父节点和向后查找儿子节点, while(pre>=0){ if(strcmp(p[pre].weidge,p[i].weidge)>=0&&strcmp(p[pre].height,p[i].height)>=0){ cout<<p[pre].ID<<" "; int post=i+1; while(post<m){ if((strcmp(p[post].weidge,p[i].weidge)<=0)&&(strcmp(p[post].height,p[i].height)<=0)){ cout<<m-post<<endl; break; }else{ post++; } } if(post==m)cout<<0<<endl; return; }else{ pre--; } } } return; } } } void main(){ // ifstream cin("data.txt"); int testcase; cin>>testcase; for(int i=0;i<testcase;i++){ cin>>m>>q; // cout<<m<<" "<<q<<endl; for(int j=0;j<m;j++){ cin>>p[j].ID>>p[j].weidge>>p[j].height; //cout<<p[j].ID<<" "<<p[j].weidge<<" "<<p[j].height<<endl; } qsort(p,m,sizeof(p[0]),cmp); /* for(j=0;j<m;j++){ cout<<p[j].ID<<" "<<p[j].weidge<<" "<<p[j].height<<endl; }*/ char query[100]; for(j=0;j<q;j++){ cin>>query; sch(query); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator