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

Why Runtime Error?

Posted by fly_away at 2006-09-09 16:48:22 on Problem 1002
#include<stdio.h>
#include<string.h>

int main()
{
	char tel[100005][20];
	char tel2[100005][20];
	char s[30], temp[30];
	unsigned long len, j, k;
	unsigned long n, i;
	unsigned long total, tag;
	while(scanf("%lu", &n) == 1)
	{
		for(i = 0;i < n;i++)
		{
			scanf("%s", s);
			len = strlen(s);
			k = 0;
			for(j = 0;j < len;j++)
			{
				if(s[j] == '-')
					continue;
				else
				{
					temp[k] = s[j];
					k++;
				}
			}
			temp[k] = '\0';
			for(j = 0;j < 7;j++)
			{
				switch(temp[j])
				{
					case 'A':
					case 'B':
					case 'C':
						temp[j] = '2';
						break;
					case 'D':
					case 'E':
					case 'F':
						temp[j] = '3';
						break;
					case 'G':
					case 'H':
					case 'I':
						temp[j] = '4';
						break;
					case 'J':
					case 'K':
					case 'L':
						temp[j] = '5';
						break;
					case 'M':
					case 'N':
					case 'O':
						temp[j] = '6';
						break;
					case 'P':
					case 'R':
					case 'S':
						temp[j] = '7';
						break;
					case 'T':
					case 'U':
					case 'V':
						temp[j] = '8';
						break;
					case 'W':
					case 'X':
					case 'Y':
						temp[j] = '9';
						break;
				}
			}
			strcpy(tel[i], temp);
		}
		k = 0;
		for(j = 0;j < 10;j++)
		{
			for(i = 0;i < n;i++)
				if(tel[i][6] == '0' + j)
				{
					strcpy(tel2[k], tel[i]);
					k++;
				}
		}
		k = 0;
		for(j = 0;j < 10;j++)
		{
			for(i = 0;i < n;i++)
				if(tel2[i][5] == '0' + j)
				{
					strcpy(tel[k], tel2[i]);
					k++;
				}
		}
		k = 0;
		for(j = 0;j < 10;j++)
		{
			for(i = 0;i < n;i++)
				if(tel[i][4] == '0' + j)
				{
					strcpy(tel2[k], tel[i]);				
					k++;
				}
		}
		k = 0;
		for(j = 0;j < 10;j++)
		{
			for(i = 0;i < n;i++)
				if(tel2[i][3] == '0' + j)
				{
					strcpy(tel[k], tel2[i]);				
					k++;
				}
		}
		k = 0;
		for(j = 0;j < 10;j++)
		{
			for(i = 0;i < n;i++)
				if(tel[i][2] == '0' + j)
				{
					strcpy(tel2[k], tel[i]);
					k++;
				}
		}
		k = 0;
		for(j = 0;j < 10;j++)
		{
			for(i = 0;i < n;i++)
				if(tel2[i][1] == '0' + j)
				{
					strcpy(tel[k], tel2[i]);
					k++;
				}
		}
		k = 0;
		for(j = 0;j < 10;j++)
		{
			for(i = 0;i < n;i++)
				if(tel[i][0] == '0' + j)
				{
					strcpy(tel2[k], tel[i]);
					k++;
				}
		}
		total = 1;
		strcpy(temp, tel2[0]);
		tag = 0;
		for(i = 1;i < n;i++)
		{
			if(strcmp(temp, tel2[i]) == 0)
			{
				total++;
				continue;
			}
			else
			{	
				if(total >= 2)
				{	
					for(j = 0;j < 7;j++)
					{
						if(j == 3)
							printf("-");
						printf("%c", temp[j]);
					}
					printf(" %lu\n", total);
					tag = 1;
					total = 1;
					strcpy(temp, tel2[i]);
				}
				else
				{	
					strcpy(temp, tel2[i]);
					total = 1;
				}
			}
		}
		if(total >= 2)
		{
				for(j = 0;j < 7;j++)
					{
						if(j == 3)
							printf("-");
						printf("%c", temp[j]);
					}
					printf(" %lu\n", total);
					tag = 1;
		}
		if(tag == 0)
			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