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 |
WA了好几次,至今没找到错误,附代码#include<iostream> #include<string> using namespace std; int count(string wish,string name[],int g,int flag[],int& m,int& n) { int count=0,i=0,j=0,k=0; for(i=0;i<wish.size();i++) { if(wish[i]>=65&&wish[i]<=90||wish[i]>=97&&wish[i]<=122) { for(j=i+1;j<wish.size();j++) { if(wish[j]>=65&&wish[j]<=90||wish[j]>=97&&wish[j]<=122) { } else break; } //cout<<wish.substr(i,j-i); count++; //cout<<wish.substr(i,j-i+1)<<endl; for(k=0;k<g;k++) { if(wish.substr(i,j-i)==name[k]) { //cout<<name[k]<<endl; flag[k]=1; m=1; } if(wish.substr(i,j-i)=="beautiful"||wish.substr(i,j-i)=="pretty"||wish.substr(i,j-i)=="lovely") n=1; } i=j; } } return count; } void slove(string name[],string wish,int g) { string temp; int flag[5]={0,0,0,0,0},i=0,j=0; int m=0,n=0; count(wish,name,g,flag,m,n); if(m==1) { for(i=0;i<g;i++) { if(flag[i]==1) { temp+=name[i]; temp+=' '; } } temp[(temp.size())-1]=':'; if(count(wish,name,g,flag,m,n)<10) cout<<temp<<" oh"<<endl; else if(n==1) cout<<temp<<" xixi"<<endl; else if(n==0) cout<<temp<<" hehe"<<endl; return; } else { temp="All: "; if(count(wish,name,g,flag,m,n)<10) cout<<temp<<"oh"<<endl; else if(n==1) cout<<temp<<"xixi"<<endl; else if(n==0) cout<<temp<<"hehe"<<endl; return; } } int main() { int g,w,i,m=0,n=0; char c; cin>>g>>w; string name[5],wish[30]; for(i=0;i<g;i++) { cin>>name[i]; } getchar(); for(i=0;i<w;i++) { while((c=getchar())!='\n') wish[i]+=c; } for(i=0;i<w;i++) { slove(name,wish[i],g); //cout<<wish[i]<<endl; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator