Skip to main content
deleted 1 character in body; edited body
Source Link
oguz ismail
  • 51.8k
  • 16
  • 64
  • 83
#include <stdio.h>

int
main(void) {
    static int n[0x99a];n[1000];
    int i, c, max;
    i = 0;
    while ((c = getchar_unlocked()) != EOF)
        if (c == '\n') {
            n[i]++;
            i = 0;
        }
        else {
            i = i<<4i*10 |+ c-'0';
        }
    max = 0;
    for (i = 1; i < sizeof n/sizeof n[0]; i++)
        if (n[i] > n[max])
            max = i;
    printf("%x\n""%d\n", max);
}
$ time ./a.out <1M_random_numbers.txt 
142

real    0m0.013s
user    0m0.008s
sys 0m0.004s005s
$ shuf -n 100000000 -i 1-999 -r >100M_random_numbers.txt
$ time ./a.out <100M_random_numbers.txt 
577867

real    0m0.327s318s
user    0m0.230s220s
sys 0m0.097s096s
$
#include <stdio.h>

int
main(void) {
    static int n[0x99a];
    int i, c, max;
    i = 0;
    while ((c = getchar_unlocked()) != EOF)
        if (c == '\n') {
            n[i]++;
            i = 0;
        }
        else {
            i = i<<4 | c-'0';
        }
    max = 0;
    for (i = 1; i < sizeof n/sizeof n[0]; i++)
        if (n[i] > n[max])
            max = i;
    printf("%x\n", max);
}
$ time ./a.out <1M_random_numbers.txt 
142

real    0m0.013s
user    0m0.008s
sys 0m0.004s
$ shuf -n 100000000 -i 1-999 -r >100M_random_numbers.txt
$ time ./a.out <100M_random_numbers.txt 
577

real    0m0.327s
user    0m0.230s
sys 0m0.097s
$
#include <stdio.h>

int
main(void) {
    static int n[1000];
    int i, c, max;
    i = 0;
    while ((c = getchar_unlocked()) != EOF)
        if (c == '\n') {
            n[i]++;
            i = 0;
        }
        else {
            i = i*10 + c-'0';
        }
    max = 0;
    for (i = 1; i < sizeof n/sizeof n[0]; i++)
        if (n[i] > n[max])
            max = i;
    printf("%d\n", max);
}
$ time ./a.out <1M_random_numbers.txt 
142

real    0m0.013s
user    0m0.008s
sys 0m0.005s
$ shuf -n 100000000 -i 1-999 -r >100M_random_numbers.txt
$ time ./a.out <100M_random_numbers.txt 
867

real    0m0.318s
user    0m0.220s
sys 0m0.096s
$
added 244 characters in body
Source Link
oguz ismail
  • 51.8k
  • 16
  • 64
  • 83
#include <stdio.h>

int
main(void) {
    static int n[0x99a];
    int i, c, max;
    i = 0;
    while ((c = getchar_unlocked()) != EOF)
        if (c == '\n') {
            n[i]++;
            i = 0;
        }
        else {
            i = i<<4 | c-'0';
        }
    max = 0;
    for (i = 1; i < sizeof n/sizeof n[0]; i++)
        if (n[i] > n[max])
            max = i;
    printf("%x\n", max);
}
$ time ./a.out <1M_random_numbers.txt 
142

real    0m0.013s
user    0m0.008s
sys 0m0.004s
$ shuf -n 100000000 -i 1-999 -r >100M_random_numbers.txt
$ time ./a.out <100M_random_numbers.txt 
577

real    0m0.327s
user    0m0.230s
sys 0m0.097s
$
#include <stdio.h>

int
main(void) {
    static int n[0x99a];
    int i, c, max;
    i = 0;
    while ((c = getchar_unlocked()) != EOF)
        if (c == '\n') {
            n[i]++;
            i = 0;
        }
        else {
            i = i<<4 | c-'0';
        }
    max = 0;
    for (i = 1; i < sizeof n/sizeof n[0]; i++)
        if (n[i] > n[max])
            max = i;
    printf("%x\n", max);
}
#include <stdio.h>

int
main(void) {
    static int n[0x99a];
    int i, c, max;
    i = 0;
    while ((c = getchar_unlocked()) != EOF)
        if (c == '\n') {
            n[i]++;
            i = 0;
        }
        else {
            i = i<<4 | c-'0';
        }
    max = 0;
    for (i = 1; i < sizeof n/sizeof n[0]; i++)
        if (n[i] > n[max])
            max = i;
    printf("%x\n", max);
}
$ time ./a.out <1M_random_numbers.txt 
142

real    0m0.013s
user    0m0.008s
sys 0m0.004s
$ shuf -n 100000000 -i 1-999 -r >100M_random_numbers.txt
$ time ./a.out <100M_random_numbers.txt 
577

real    0m0.327s
user    0m0.230s
sys 0m0.097s
$
Source Link
oguz ismail
  • 51.8k
  • 16
  • 64
  • 83

#include <stdio.h>

int
main(void) {
    static int n[0x99a];
    int i, c, max;
    i = 0;
    while ((c = getchar_unlocked()) != EOF)
        if (c == '\n') {
            n[i]++;
            i = 0;
        }
        else {
            i = i<<4 | c-'0';
        }
    max = 0;
    for (i = 1; i < sizeof n/sizeof n[0]; i++)
        if (n[i] > n[max])
            max = i;
    printf("%x\n", max);
}