Submission #18210


Source Code Expand

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

char s[100][21];
int p[100], q[100];

int cmp(const void *a, const void *b)
{
    int x = *((int *)a);
    int y = *((int *)b);
    int i;
    
    for (i = 0; i < p[x] && i < p[y]; i++) {
        if (s[x][p[x] - i - 1] == s[y][p[y] - i - 1]) continue;
        
        if (s[x][p[x] - i - 1] < s[y][p[y] - i - 1]) {
            return -1;
        } else {
            return 1;
        }
    }
    
    if (i == p[x]) {
        return -1;
    } else {
        return 1;
    }
}

int main()
{
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%s", s[i]);
        
        p[i] = strlen(s[i]);
        q[i] = i;
    }
    
    qsort(q, n, sizeof(int), cmp);
    
    for (i = 0; i < n; i++) printf("%s\n", s[q[i]]);
    
    return 0;
}

Submission Info

Submission Time
Task B - さかさま辞書
User kawatea
Language C (GCC 4.4.7)
Score 100
Code Size 885 Byte
Status AC
Exec Time 23 ms
Memory 692 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:35: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
./Main.c:38: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 28
Set Name Test Cases
all 00_sample_01.txt, 00_sample_02.txt, 01_rand_01.txt, 01_rand_02.txt, 01_rand_03.txt, 01_rand_04.txt, 01_rand_05.txt, 01_rand_06.txt, 01_rand_07.txt, 01_rand_08.txt, 01_rand_09.txt, 01_rand_10.txt, 02_long_01.txt, 02_long_02.txt, 02_long_03.txt, 03_short_01.txt, 03_short_02.txt, 03_short_03.txt, 04_max_01.txt, 04_max_02.txt, 04_max_03.txt, 04_max_04.txt, 04_max_05.txt, 05_samestring_01.txt, 05_samestring_02.txt, 05_samestring_03.txt, 05_samestring_04.txt, 05_samestring_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 21 ms 676 KB
00_sample_02.txt AC 19 ms 672 KB
01_rand_01.txt AC 19 ms 660 KB
01_rand_02.txt AC 22 ms 692 KB
01_rand_03.txt AC 20 ms 664 KB
01_rand_04.txt AC 21 ms 664 KB
01_rand_05.txt AC 21 ms 660 KB
01_rand_06.txt AC 19 ms 680 KB
01_rand_07.txt AC 21 ms 656 KB
01_rand_08.txt AC 21 ms 680 KB
01_rand_09.txt AC 19 ms 660 KB
01_rand_10.txt AC 20 ms 660 KB
02_long_01.txt AC 20 ms 684 KB
02_long_02.txt AC 20 ms 680 KB
02_long_03.txt AC 20 ms 664 KB
03_short_01.txt AC 20 ms 676 KB
03_short_02.txt AC 23 ms 680 KB
03_short_03.txt AC 20 ms 664 KB
04_max_01.txt AC 22 ms 660 KB
04_max_02.txt AC 21 ms 672 KB
04_max_03.txt AC 19 ms 668 KB
04_max_04.txt AC 21 ms 668 KB
04_max_05.txt AC 20 ms 684 KB
05_samestring_01.txt AC 21 ms 684 KB
05_samestring_02.txt AC 20 ms 652 KB
05_samestring_03.txt AC 22 ms 680 KB
05_samestring_04.txt AC 21 ms 672 KB
05_samestring_05.txt AC 21 ms 680 KB