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

谢谢discuss的数据,RE是因为a%b时b=0引起的,附AC代码

Posted by yzhw at 2009-04-21 17:20:08 on Problem 1107
Source Code

Problem: 1107  User: yzhw 
Memory: 436K  Time: 0MS 
Language: G++  Result: Accepted 

Source Code 
# include <iostream>
# include <cstring>
using namespace std;
char ori[100],t1[100],t2[100],t3[100];
int k1,k2,k3,c1,c2,c3,n1[100],n2[100],n3[100];
int main()
{
	while(1)
	{
		cin>>k1>>k2>>k3;
		if(!k1&&!k2&&!k3) break;
		cin>>ori;
		//初始化
		c1=c2=c3=0;
		for(int i=0;i<strlen(ori);i++)
		{
			if(ori[i]>='a'&&ori[i]<='i')
			{
				t1[++c1]=ori[i];
				n1[c1]=i;
			}
			else if(ori[i]>='j'&&ori[i]<='r')
			{
				t2[++c2]=ori[i];
				n2[c2]=i;
			}
			else
			{
				t3[++c3]=ori[i];
				n3[c3]=i;
			}
		}
		//循环覆盖
		if(k1&&c1)
		for(int i=1-k1%c1;i<1-k1%c1+c1;i++)
		{
			if(i<=0)
			{
				ori[n1[i+k1%c1]]=t1[c1+i];
			}
			else
			{
				ori[n1[i+k1%c1]]=t1[i];
			}
		}
		if(k2&&c2)
		for(int i=1-k2%c2;i<1-k2%c2+c2;i++)
		{
			if(i<=0)
			{
				ori[n2[i+k2%c2]]=t2[c2+i];
			}
			else
			{
				ori[n2[i+k2%c2]]=t2[i];
			}
		}
		if(k3&&c3)
		for(int i=1-k3%c3;i<1-k3%c3+c3;i++)
		{
			if(i<=0)
			{
				ori[n3[i+k3%c3]]=t3[c3+i];
			}
			else
			{
				ori[n3[i+k3%c3]]=t3[i];
			}
		}
		cout<<ori<<endl;
	}
	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