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

我的TLE了,哪位大牛给看看

Posted by Pro_zq at 2009-08-17 10:04:37 on Problem 1002
这是我的源代码,思路是一般的思路:

#include <stdio.h>
#include <string.h>

int main()
{
    int n; //n个电话号码
    int showCnt; //某个电话号码出现的次数
    int i, j, k; //循环变量

    char numList[100000][20]; //存输入的、处理后的电话号码
    char tmp[20]; //中间变量,排序时使用
    char notPrint = 1; //标记变量,置1表示没有打印

    scanf("%d", &n);
    for(i = 0; i < n; ++i)
    {
        scanf("%s", tmp);

        //将输入的电话号码编程纯数字的形式
        for(j = 0, k = 0; j < strlen(tmp); ++j)
        {
            if(tmp[j] >= '0' && tmp[j] <= '9')
            {
                tmp[k++] = tmp[j];
            }
            else
            {
                switch(tmp[j])
                {
                    case 'A':
                    case 'B':
                    case 'C':
                        tmp[k++] = '2';
                        break;

                    case 'D':
                    case 'E':
                    case 'F':
                        tmp[k++] = '3';
                        break;

                    case 'G':
                    case 'H':
                    case 'I':
                        tmp[k++] = '4';
                        break;

                    case 'J':
                    case 'K':
                    case 'L':
                        tmp[k++] = '5';
                        break;

                    case 'M':
                    case 'N':
                    case 'O':
                        tmp[k++] = '6';
                        break;

                    case 'P':
                    case 'R':
                    case 'S':
                        tmp[k++] = '7';
                        break;

                    case 'T':
                    case 'U':
                    case 'V':
                        tmp[k++] = '8';
                        break;

                    case 'W':
                    case 'X':
                    case 'Y':
                        tmp[k++] = '9';
                        break;
                } //end of switch
            }
        } // end of for
        tmp[k] = 0;

        strcpy(numList[i] ,tmp); //将处理完的电话号码存入数组
    }

    //选择排序,升序
    for(i = 0; i < n - 1; ++i)
    {
        k = i;

        for(j = i + 1; j < n; ++j)
        {
            if(strcmp(numList[j], numList[k]) < 0)
            {
                k = j;
            }
        }

        if(k != i)
        {
            strcpy(tmp, numList[i]);
            strcpy(numList[i], numList[k]);
            strcpy(numList[k], tmp);
        }
    }

    //检查输出
    for(i = 0; i < n - 1; i += showCnt)
    {
        showCnt = 1;

        for(j = i + 1; j < n; ++j)
        {
            if(!strcmp(numList[i], numList[j]))
            {
                showCnt++;
            }
        }

        if(showCnt > 1)
        {
            printf("%c%c%c-", numList[i][0], numList[i][1], numList[i][2]);
            printf("%s %d\n", numList[i] + 3, showCnt);

            notPrint = 0;
        }
    }

    if(notPrint)
    {
        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