first commit

This commit is contained in:
Antonia 2022-12-03 02:26:39 +01:00
commit a3e682fea3
4 changed files with 175 additions and 0 deletions

23
01.c Normal file
View file

@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
char cur[20];
int cur_sum = 0;
int max = 0;
while (fgets(cur,20,stdin) != NULL) {
if (strlen(cur) > 1) {
cur_sum += atoi(cur);
if (cur_sum > max) {
max = cur_sum;
}
} else {
cur_sum = 0;
}
}
printf("%d\n", max);
}

29
01_02.c Normal file
View file

@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
char cur[20];
int cur_sum = 0;
int max = 0;
int second = 0;
int third = 0;
while (fgets(cur,20,stdin) != NULL) {
if (strlen(cur) > 1) {
cur_sum += atoi(cur);
if (cur_sum > max) {
max = cur_sum;
} else if (cur_sum > second) {
second = cur_sum;
} else if (cur_sum > third) {
third = cur_sum;
}
} else {
cur_sum = 0;
}
}
printf("%d\n", max+second+third);
}

47
02.c Normal file
View file

@ -0,0 +1,47 @@
#include <stdio.h>
#define ROCK 1
#define PAPER 2
#define SCISSORS 3
int norm_symb(char s) {
int r = (int) s - 0x40;
if (r > 3 ) {
r -= 0x17;
}
return r;
}
int score(int p1, int p2) {
if (p1 == p2) {
return 3;
}
switch (p2) {
case ROCK:
if (p1 == SCISSORS) return 6;
break;
case PAPER:
if (p1 == ROCK) return 6;
break;
case SCISSORS :
if (p1 == PAPER) return 6;
break;
}
return 0;
}
int main () {
char cur[20];
int p1;
int p2;
int sc = 0;
while (fgets(cur,20,stdin) != NULL) {
p1 = norm_symb(cur[0]);
p2 = norm_symb(cur[2]);
printf("%d %d %d\n", p1,p2, score(p1,p2));
sc += (score(p1,p2) + p2);
}
printf("%d\n", sc);
}

76
02_02.c Normal file
View file

@ -0,0 +1,76 @@
#include <stdio.h>
#define ROCK 1
#define PAPER 2
#define SCISSORS 3
int norm_symb(char s) {
int r = (int) s - 0x40;
if (r > 3 ) {
r -= 0x17;
}
return r;
}
int score(int p1, int p2) {
if (p1 == p2) {
return 3;
}
switch (p2) {
case ROCK:
if (p1 == SCISSORS) return 6;
break;
case PAPER:
if (p1 == ROCK) return 6;
break;
case SCISSORS :
if (p1 == PAPER) return 6;
break;
}
return 0;
}
int symb (int p1, int outcome) {
if (outcome == 2) return p1;
if (outcome == 1) { // need to lose
switch (p1) {
case ROCK:
return SCISSORS;
break;
case PAPER:
return ROCK;
break;
case SCISSORS:
return PAPER;
break;
}
}
switch (p1) { // need to win
case ROCK:
return PAPER;
break;
case PAPER:
return SCISSORS;
break;
case SCISSORS:
return ROCK;
break;
}
}
int main () {
char cur[20];
int p1;
int p2;
int sc = 0;
while (fgets(cur,20,stdin) != NULL) {
p1 = norm_symb(cur[0]);
p2 = symb(p1,norm_symb(cur[2]));
printf("%d %d %d\n", p1,p2, score(p1,p2));
sc += (score(p1,p2) + p2);
}
printf("%d\n", sc);
}