solved 3 in sufficiently short runtime
This commit is contained in:
parent
414cdf7f63
commit
e1fe054f63
2 changed files with 75 additions and 0 deletions
13
3/Makefile
Normal file
13
3/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
client: main.c
|
||||||
|
gcc -o main main.c -O3 -Wall -Wextra -g -march=x86-64-v3
|
||||||
|
|
||||||
|
client-debug: main.c
|
||||||
|
gcc -o main main.c -O1 -Wall -Wextra -g -fsanitize=address
|
||||||
|
|
||||||
|
client-debug-nosanitize: main.c
|
||||||
|
gcc -o main main.c -O1 -Wall -Wextra -g
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm main
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
62
3/main.c
Normal file
62
3/main.c
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
char input[] =
|
||||||
|
{
|
||||||
|
#embed "input.txt"
|
||||||
|
,'\0' // null terminator
|
||||||
|
};
|
||||||
|
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
clock_t start, end;
|
||||||
|
start = clock();
|
||||||
|
|
||||||
|
while(input[width] != '\n'){
|
||||||
|
width++;
|
||||||
|
}
|
||||||
|
//printf("width: %d\n", width);
|
||||||
|
|
||||||
|
while(input[height*(width+1)+1] != 0){
|
||||||
|
height++;
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
for(int i = 0; i < height; i++){
|
||||||
|
int biggest = input[i*(width+1)];
|
||||||
|
int second_biggest = input[i*(width+1)+1];
|
||||||
|
for(int o = 0; o < width-1; o++){
|
||||||
|
|
||||||
|
int num = input[i*(width+1)+o];
|
||||||
|
if(num>biggest){
|
||||||
|
biggest = num;
|
||||||
|
second_biggest = input[i*(width+1)+o+1];
|
||||||
|
}else if(second_biggest < input[i*(width+1)+o+1]){
|
||||||
|
second_biggest = input[i*(width+1)+o+1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count += (biggest-0x30)*10 + (second_biggest-0x30);
|
||||||
|
for(int i = 0; i<12; i++){
|
||||||
|
|
||||||
|
}
|
||||||
|
//printf(input);
|
||||||
|
//printf("count: %d\n", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
end = clock();
|
||||||
|
printf("count: %d\n", count);
|
||||||
|
clock_t ticks_taken = end - start;
|
||||||
|
double time_taken = ((double)ticks_taken)/CLOCKS_PER_SEC;
|
||||||
|
printf("time take: %f ticks\n", time_taken);
|
||||||
|
printf("CLOCKS_PER_SEC: %ld\n", CLOCKS_PER_SEC);
|
||||||
|
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue