Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一直Output Limit Exceeded,请求大牛指点啊!

Posted by xuezhongfenfei at 2012-11-19 20:16:50 on Problem 1602
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator