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 wf103 at 2020-03-16 17:50:39
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int change(char t){
    if(t >= 'A' && t <= 'C') return 2;
    else if(t >= 'D' && t <= 'F') return 3;
    else if(t >= 'G' && t <= 'I') return 4;
    else if(t >= 'J' && t <= 'L') return 5;
    else if(t >= 'M' && t <= 'O') return 6;
    else if(t >= 'P' && t <= 'S') return 7;
    else if(t >= 'T' && t <= 'V') return 8;
    else if(t >= 'W' && t <= 'Y') return 9;
    return 0;
}
void read(int num[], int n){
    char s[200]; 
    int temp, t;
    for(int i = 0; i < n; i++){
        scanf("%s", s);
        t = 0;
        for(int j = 0; j < 199; j++){
            if(t == 7) break;
            if(s[j] >= '0' && s[j] <= '9'){
                num[i] += ((int)s[j] - 48) * pow(10, 6 - t);
                t++;
            }else if(s[j] >= 'A' && s[j] <= 'Y' && s[j] != 'Q'){
                temp = change(s[j]);
                num[i] += temp * pow(10, 6 - t);
                t++;
            }
        
        }
    }
}

void Qsort(int num[], int left, int right){
    int temp, k = num[left], l = left, r = right;
    if(l < r){
        while(l < r){
            while(l < r && num[r] > k) r--;
            num[l] = num[r];
            while(l < r && num[l] <= k) l++;
            num[r] = num[l];
        }
        num[l] = k;
        Qsort(num, left, l - 1);
        Qsort(num, l + 1, right);
    }
}

void print(int num[], int n){
    int t = 1;
    int p = 0;
    for(int i = 0; i < n - 1; i++){
        if(num[i] == num[i + 1]){
            if(t == 1){
                printf("%03d-%04d ", num[i] / 10000, num[i] % 10000);
                t++;
            }else t++;
        }else if(t != 1){
            printf("%d\n", t);
            t = 1;
            p = 1;
        }
    }
    if(t != 1){
        printf("%d\n", t);
        p = 1;
    }
    if(p == 0) printf("No duplicates.\n");
}

int main(){
    int n;
    scanf("%d", &n);
    int *num = (int*)malloc(n * sizeof(int));
    read(num, n);
    Qsort(num, 0, n - 1);
    print(num, n);
    free(num);
    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