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 |
一直Output Limit Exceeded,请求大牛指点啊!#include<iostream> #include<string> using namespace std; void funa(char a[], int len) { char b[10005],i; int p,j,k=1; if(len==1) { cout<<a[1]<<endl; cout<<len<<endl; return ; } for(i='a'; i<='z'; i++) { for(j=1; j<=len; j++) { if(a[j]==i) { if(j==2) p=k; if(j-1==0) b[k++]=a[len]; else b[k++]=a[j-1]; } } } for(i=1; i<=len; i++) cout<<b[i]; cout<<endl; cout<<p<<endl; } void funb(char a[],int len, int p) { char b[10005]; int i; b[1]=a[p]; //这个是头的 for(i=1; i<=len; i++) if(a[i]==a[p]) break; b[len]=a[i];//这个是尾的 int w[27]; for(i=0; i<=26; i++)//记录字母的出现的 w[i]=0; for(i=1; i<=len; i++) w[a[i]-96]++; for(i=1; i<=26; i++) w[i]+=w[i-1]; for(i=len-1; i>1; i--)//从后向前的 { b[i]=a[w[b[i+1]-96]]; w[b[i+1]-96]--; } for(i=1; i<=len; i++) cout<<b[i]; cout<<endl; } int main() { char x,a[10005]; int p,len,i; cin>>x; cin>>len; cin>>a; for(i=len; i>=1; i--) a[i]=a[i-1]; if(x=='A') funa(a,len); if(x=='B') { cin>>p; funb(a,len,p); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator