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

Re:为什么我的代码WA?

Posted by hanhui8301 at 2017-05-14 03:10:22 on Problem 1002
In Reply To:为什么我的代码WA? Posted by:nullptr at 2017-02-01 16:29:41
> #include <cstdio>
> #include <algorithm>
> using namespace std;
> int main()
> {
> 	int nums[100000];
> 	char s[16],*p;
> 	int n,t,sum,i,ct=1;
> 	bool b=false;
> 	scanf("%d",&n);
> 	for (i=0;i<n;i++)
> 	{
> 		scanf("%s",s);
> 		sum=0;
> 		for (p=s;*p;p++)
> 		{
> 			t=0;
> 			if (*p>='0'&&*p<='9')
> 				t=*p-'0';
> 			else if (*p>='A'&&*p<'Z')
> 			{
> 				if (*p<'Q')
> 					t=(*p-'A')/3+2;
> 				else
> 					t=(*p-'A'-1)/3+2;
> 			}
> 			else
> 				continue;
> 			sum=sum*10+t;
> 		}
> 		nums[i]=sum;
> 	}
> 	std::sort(nums,nums+n);
> 	/*
> 	for (i=1;i<n;i++)
> 	{
> 		if (nums[i]==nums[i-1])
> 			ct++;
> 		else
> 		{
> 			if (ct>1)
> 			{
> 				printf("%03d-%04d %d\n",nums[i-1]/10000,nums[i-1]%10000,ct);
> 				b=true;
> 			}
> 			ct=1;
> 		}
> 	}
> 	*/
> 	for (i=1;;)
> 	{
> 		ct=1;
> 		while (nums[i]==nums[i-1]&&i<n)
> 		{
> 			ct++;
> 			i++;
> 		}
> 		if (ct>1)
> 		{
> 			printf("%03d-%04d %d\n",nums[i-1]/10000,nums[i-1]%10000,ct);
> 			b=true;
> 		}
> 		i++;
> 		if (i>=n)
> 			break;
> 	}
> 	if (!b)
> 		printf("No duplicates.\n");
> }

nums未初始化, n=1时有问题

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