commit a3e682fea34051010f07f4e1f497ad1d30df9cb7 Author: Antonia Date: Sat Dec 3 02:26:39 2022 +0100 first commit diff --git a/01.c b/01.c new file mode 100644 index 0000000..4d4bbf8 --- /dev/null +++ b/01.c @@ -0,0 +1,23 @@ +#include +#include +#include + +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); + +} diff --git a/01_02.c b/01_02.c new file mode 100644 index 0000000..d68e653 --- /dev/null +++ b/01_02.c @@ -0,0 +1,29 @@ +#include +#include +#include + +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); + +} diff --git a/02.c b/02.c new file mode 100644 index 0000000..3b010a4 --- /dev/null +++ b/02.c @@ -0,0 +1,47 @@ +#include + +#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); +} diff --git a/02_02.c b/02_02.c new file mode 100644 index 0000000..c9edbe7 --- /dev/null +++ b/02_02.c @@ -0,0 +1,76 @@ +#include + +#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); +}