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

C的AC代码,提醒:输入的字符数组长度至少50(40肯定不行)

Posted by rhythm1 at 2018-11-18 23:39:59 on Problem 1002
/* 1002 */
#include <stdio.h>
#include <stdlib.h>
#define L 100000

int cmp(const void * a, const void * b)
{
	return *(int *)a - *(int *)b;
}

int
main()
{
    int tel[L];
    char temp[100], c;
    int n, flag = 0;
    int i, j;
    int iTemp, num;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s", temp);
        j = 0;
        iTemp = 0;
        while (temp[j] != '\0') {
            c = temp[j++];
            if (c != '-') {
                if (c >= '0' && c <= '9')
                    c -= '0';
                else
                switch(c) {
                case 'A': case 'B': case 'C':
                    c = 2;
                    break;
                case 'D': case 'E': case 'F':
                    c = 3;
                    break;
                case 'G': case 'H': case 'I':
                    c = 4;
                    break;
                case 'J': case 'K': case 'L':
                    c = 5;
                    break;
                case 'M': case 'N': case 'O':
                    c = 6;
                    break;
                case 'P': case 'R': case 'S':
                    c = 7;
                    break;
                case 'T': case 'U': case 'V':
                    c = 8;
                    break;
                case 'W': case 'X': case 'Y':
                    c = 9;
                    break;
                }
                iTemp = iTemp*10 + c;
            }
        }
        tel[i] = iTemp;
    }
    /* 操作 */
	qsort(tel, n, sizeof(int), cmp);
	/* Output */
    for (i = 0, tel[n] = 0; i < n; i++) {
        num = 1;
        while (tel[i] == tel[i+1]) {
            num++;
            i++;
        }
        if (num > 1) {
            printf("%03d-%04d %d\n", tel[i]/10000, tel[i]%10000, num);
            flag = 1;
        }
    }
    if (flag == 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