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 |
坑爹题目怎么代码都没错就是Runtime Error#include <iostream> #include <string> using namespace std; string a[10101],b[10101]; int n; void qs(int s,int t) { if (s>=t) return; int i=s,j=t; string k=b[(i+j)>>1]; while (i<=j) { while (i<=j&&b[i]>k)i++; while (i<=j&&b[j]<k)j--; if (i<=j) { string ex=a[i];a[i]=a[j];a[j]=ex; ex=b[i];b[i]=b[j];b[j]=ex; i++; j--; } } qs(s,j); qs(i,t); } int main() { n=0; string s; while (getline(cin,s)) { if (s=="") break; int m=s.find(' '); a[++n]=s.substr(0,m); b[n]=s.substr(m+1,s.length()); } qs(1,n); while (cin>>s) { int l=1,r=n,m; do{ m=(l+r)>>1; if (s>b[m]) r=m; else l=m; }while (l+3<r); bool ok=false; int i; for (i=l;i<=r;i++) if (b[i]==s) {ok=true; break;} if (ok) cout<<a[i]<<endl; else cout<<"eh\n"; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator