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,不知道哪里错了,自己做的测试数据都没有问题啊!

Posted by Professor_G at 2006-12-09 00:46:32 on Problem 1002
#include<stdio.h>
#include<algorithm>
using namespace std;

int main()
{
	int array[100001];//用于存储号码信息
	char map[] = "22233344455566677778889999";//转换时查表用
    memset(array,0,100001);//把array的元素都设为0
	char temp[100];//用于接收输入信息
	long n,k=0;//n是接收n个号码的个数,k是一个下标
	int count=1;//用于计数相同的号码个数,用于判断和输出
    bool open=false;//判断是否各个号码都不相同

    scanf("%d",&n);//接收个数信息
	while(k<n)//接收号码信息和转换操作
	{
		scanf("%s",temp);
		for(int i=0;temp[i];i++)
		{
			if(temp[i]!='-')
			{
				if(temp[i]<='9'&&temp[i]>='0')
				{
					array[k] = array[k]*10 + temp[i] - '0';
				}
				else 
					array[k] = array[k]*10 + map[temp[i] - 'A'] - '0';
			}
		}
		k++;
	}
	
	sort(array,array+n);//排序

    for(k=0;k<n-1;k++)//输出
	{

		if(array[k] == array[k+1])
		{
			open = true;
			count++;
		}

		else if(count!=1)
		{
			printf("%03d-%04d %d\n",array[k]/10000,array[k]%10000,count);
			count = 1;
		}
	}
	
	if(count!=1)
	{
			printf("%03d-%04d %d\n",array[k]/10000,array[k]%10000,count);
			count = 1;
	}

	if(open == false)
		printf("No duplicates.\n");//无相同号码
	
    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