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

难道这样也错了吗、?????

Posted by win1611 at 2010-02-02 16:56:34 on Problem 2895
#include<stdio.h>
#include<string.h>

int main()
{
	int t,p,w;
	int i,j,len,time,num=0;
	char str[1010],prev;
	char code[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
	while(scanf("%d%d%d",&t,&p,&w)!=EOF)
	{
		if(num++>t)	break;        //如果测试的案例超过输入的 则需退出循环
		getchar();
		gets(str);
		len=strlen(str);
		prev='\0';                //保存前面的字符,若现在的字符与前面的字符相等则时间上需要再加上10s
		time=0;
		for(i=0;i<len;i++)
		{
			time+=2;
			if(code[str[i]-'A']==prev)
			{
				time+=10;
				j=1;
				while(code[str[i]-'A'-j]&&code[str[i]-'A'-j]==prev)//求出此字符需要按的次数 即需要等待的时间time
				{
					time+=2;
					j++;
				}
			}
			else
			{
				j=1;
				while(str[i]-'A'>=0&&code[str[i]-'A'-j]==code[str[i]-'A'])
				{
					time+=2;
					j++;
				}
			}
			if(str[i]==' ')
				prev=' ';
			else
				prev=code[str[i]-'A'];
		}
		printf("%d\n",time);
	}
	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