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

晚上怎么改都WA,早上起来,一次AC,还是早上清醒啊!!!

Posted by sdau_085111 at 2011-01-08 07:28:10 on Problem 2895 and last updated at 2011-01-08 07:28:41
/* Author : yan
 * Question : POJ 2895 Best SMS to Type
 * Data && Time : Friday, January 07 2011 11:16 PM
 * Compiler : gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
*/
#include<stdio.h>
//对应键需要按的次数,最后一个是空格
int dic[]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4,1};
//对应字符对应键
int dic1[]={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,1};

char mesg[1005];

int main()
{
	//freopen("input","r",stdin);
	int test;
	int press,wait;
	int i;
	int ans;
	int cnt;//空格个数
	scanf("%d",&test);
	while(test--)
	{
		ans=0;cnt=0;
		scanf("%d %d",&press,&wait);
		getchar();
		gets(mesg);
		for(i=0;mesg[i+1]!='\0';i++)
		{
			if(mesg[i+1]==32) mesg[i+1]='A'+26;
			if( dic1[mesg[i]-'A']==dic1[mesg[i+1]-'A'] && dic1[mesg[i]-'A']!=1 )
			{
				ans+=press*dic[mesg[i]-'A']+wait;
				//printf("%d\n",press*dic[mesg[i]-'A']+wait);
			}
			else
			{
				ans+=press*dic[mesg[i]-'A'];
				//printf("%d\n",press*dic[mesg[i]-'A']);
			}
		}
		//printf("%c",mesg[i]);
		ans+=press*dic[mesg[i]-'A'];
		printf("%d\n",ans);
	}
	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