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

Runtime Error

Posted by 201201050930 at 2013-01-28 15:34:34 on Problem 1002
那位大神帮忙看一下,不胜感激!!!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100+10
#define MAX_ 100000+10
int main()
{
    int a,i,j,x,y,count,c=0;
    char phone[MAX_][MAX],t_phone[MAX_][MAX],true_phone[MAX_][MAX],swap[MAX];
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d\n",&a);
    for(i=0,x=0; i<a; i++,x++)
    {
        gets(phone[i]);
        for(j=0,y=0; phone[i][j]!=0; j++)
        {
            if(isalpha(phone[i][j])||(phone[i][j]>='0'&&phone[i][j]<='9'))
            {
                t_phone[x][y]=phone[i][j];
                y++;
            }
        }
        t_phone[x][y]=0;
    }
    for(x=0; x<a; x++)
    {
        for(y=0; t_phone[x][y]!=0; y++)
        {
            if(isalpha(t_phone[x][y]))
            {
                switch(t_phone[x][y])
                {
                case 'A':
                case 'B':
                case 'C':
                    true_phone[x][y]='2';
                    break;
                case 'D':
                case 'E':
                case 'F':
                    true_phone[x][y]='3';
                    break;
                case 'G':
                case 'H':
                case 'I':
                    true_phone[x][y]='4';
                    break;
                case 'J':
                case 'K':
                case 'L':
                    true_phone[x][y]='5';
                    break;
                case 'M':
                case 'N':
                case 'O':
                    true_phone[x][y]='6';
                    break;
                case 'P':
                case 'R':
                case 'S':
                    true_phone[x][y]='7';
                    break;
                case 'T':
                case 'U':
                case 'V':
                    true_phone[x][y]='8';
                    break;
                default:
                    true_phone[x][y]='9';
                    break;
                }
            }
            else
                true_phone[x][y]=t_phone[x][y];
        }
        true_phone[x][y]=0;
    }
    for(i=0; i<a; i++)
    {
        for(j=i+1; j<a; j++)
            if(strcmp(true_phone[i],true_phone[j])==1)
            {
                strcpy(swap,true_phone[i]);
                strcpy(true_phone[i],true_phone[j]);
                strcpy(true_phone[j],swap);
            }
    }
    for(i=0; i<a;)
    {
        count=1;
        for(j=i+1; j<a; j++)
        {
            if(strcmp(true_phone[i],true_phone[j])==0)
                count++;
            else
                break;
        }
        if(count!=1)
        {
            c=1;
            for(x=0;x<3;x++)
            printf("%c",true_phone[i][x]);
            printf("-");
            for(;x<7;x++)
                printf("%c",true_phone[i][x]);
            printf(" %d\n",count);
        }
        i=j;
    }
    if(c==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