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

Re:k+=1;错了...不应该让它跳开==>tem[k]数组也跳开了

Posted by wsbear at 2006-08-04 08:53:59 on Problem 2685
In Reply To:Why wrong answer ? Who can tell me ? Thank you !!! Codes here please :) Posted by:123454321 at 2006-07-20 20:51:21
> #include<stdio.h>
> struct num{
> 	int key;
> 	char mcxi;
> };
> int deal1(char s[])
> {
> 	int i,k,j,sum;
> 	struct num tem[99];
> 	for(k=0,i=0;s[k];k++,i++)
> 	{
> 		if(s[k]=='m'||s[k]=='c'||s[k]=='x'||s[k]=='i')
> 		{
> 			tem[i].key=1;
> 			tem[i].mcxi=s[k];
> 		}
> 		else
> 		{
> 			tem[i].key=s[k]-'0';
> 			tem[i].mcxi=s[k+1];//用i来保持数组连续...
> 			k+=1;
> 		}
> 	}
> 	sum=0;
> 	for(j=0;j<i;j++)//修改k为i
> 		switch(tem[j].mcxi) {
> 	case 'm' :sum+=tem[j].key*1000;break;
> 	case 'c' :sum+=tem[j].key*100;break;
> 	case 'x' :sum+=tem[j].key*10;break;
> 	case 'i' :sum+=tem[j].key;break;
> 		}
> 		return sum;
> }
>
>
>
> int main()
> {
> 	register int k,j;
> 	int total,sum,sum1,sum2;
> 	char s1[19],s2[19];
> 	struct num d[5];
> 	scanf("%d",&total);
> 	while(total--)
> 	{
> 		scanf("%s%s",s1,s2);
> 		sum1=deal1(s1);
> 		sum2=deal1(s2);
> 		sum=sum1+sum2;
> 		//deal2(sum);
> 		for(k=1;sum>0 && k<5;k++)
> 		{
> 			d[k].key=sum%10;
> 			sum=sum/10;
> 		}
> 		d[1].mcxi='i';
> 		d[2].mcxi='x';
> 		d[3].mcxi='c';
> 		d[4].mcxi='m';
> 		//print();
> 		for(j=k-1;j>0;j--)
> 			if(d[j].key==0) continue;
> 			else if(d[j].key==1) printf("%c",d[j].mcxi);
> 			else printf("%d%c",d[j].key,d[j].mcxi);
> 		printf("\n");
>
> 	}
> 	return 0;
> }

Followed by: