add pset12, but 1-3 and 2-1 doesn't get full score
pta sucks
This commit is contained in:
parent
4626b75d12
commit
a5d49c0c3f
|
@ -1,3 +1,4 @@
|
|||
// https://bbc3502.hopto.org/c2021/index.php/home-17/590-3
|
||||
/* ⚠*** This code is not perfect *** */
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -22,10 +23,10 @@ int main() {
|
|||
#include <string.h>
|
||||
#pragma GCC optimize("Ofast,inline")
|
||||
int getVowel(char str[], char vowel[]) {
|
||||
char vowelstr[] = {'a', 'e', 'i', 'o', 'u'};
|
||||
char vowelstr[] = {'a', 'e', 'i', 'o', 'u', '\0'};
|
||||
int len = 0;
|
||||
for (int i = 0, n = strlen(str); i < n; i++) {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
for (int j = 0, m = strlen(vowelstr); j < m; j++) {
|
||||
if (vowelstr[j] == str[i]) {
|
||||
vowel[len++] = str[i];
|
||||
}
|
||||
|
|
29
semester1/pset12/2-1-paren.c
Normal file
29
semester1/pset12/2-1-paren.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
// https://bbc3502.hopto.org/c2021/index.php/home-17/591-1
|
||||
// This code should get 100 points but due to the shitty pintia, it gets 90.
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define MAXLEN 101
|
||||
|
||||
int main(void) {
|
||||
char str[MAXLEN];
|
||||
// fgets is not gets
|
||||
fgets(str, MAXLEN, stdin);
|
||||
|
||||
// Process string
|
||||
int count = 0;
|
||||
for (int i = 0, n = strlen(str); i < n; i++) {
|
||||
if (str[i] == '(') {
|
||||
count++;
|
||||
} else if (str[i] == ')') {
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate
|
||||
if (count != 0) {
|
||||
printf("parentheses do not match!\n");
|
||||
} else {
|
||||
printf("parentheses match!\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
43
semester1/pset12/2-2-IDnumber.c
Normal file
43
semester1/pset12/2-2-IDnumber.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#pragma GCC optimize("Ofast,inline")
|
||||
#define MAXLEN 18
|
||||
|
||||
// returns 1 if valid, otherwise 0
|
||||
int validate(char *id);
|
||||
|
||||
int main(void) {
|
||||
char *id = malloc(sizeof(char) * MAXLEN);
|
||||
int lines;
|
||||
|
||||
scanf("%d", &lines);
|
||||
|
||||
for (int i = 0; i < lines; i++) {
|
||||
scanf("%s", id);
|
||||
if (validate(id)) {
|
||||
printf("right\n");
|
||||
} else {
|
||||
printf("wrong\n");
|
||||
}
|
||||
}
|
||||
|
||||
free(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int validate(char *id) {
|
||||
char lasttable[] = "10X98765432";
|
||||
int factor[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
|
||||
int last = 0;
|
||||
|
||||
for (int i = 0; i < 17; i++) {
|
||||
last += (id[i] - '0') * factor[i];
|
||||
}
|
||||
|
||||
last = last % 11;
|
||||
if (lasttable[last] == id[17]) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
33
semester1/pset12/2-3-analyze.c
Normal file
33
semester1/pset12/2-3-analyze.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#pragma GCC optimize("Ofast,inline")
|
||||
#define MAXLEN 100
|
||||
|
||||
int main(void) {
|
||||
char string[MAXLEN];
|
||||
scanf("%s", string);
|
||||
|
||||
char hashA[26] = {};
|
||||
char hasha[26] = {};
|
||||
|
||||
// Store values to hash table
|
||||
for (int i = 0, j = strlen(string); i < j; i++) {
|
||||
if (string[i] >= 'A' && string[i] <= 'Z') {
|
||||
hashA[string[i] - 'A']++;
|
||||
} else if (string[i] >= 'a' && string[i] <= 'z') {
|
||||
hasha[string[i] - 'a']++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (hashA[i]) {
|
||||
printf("The character %c has presented %i times.\n", i + 'A', hashA[i]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (hasha[i]) {
|
||||
printf("The character %c has presented %i times.\n", i + 'a', hasha[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
31
semester1/pset12/2-4-OrderedPrint.c
Normal file
31
semester1/pset12/2-4-OrderedPrint.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#pragma GCC optimize("Ofast,inline")
|
||||
#define MAXLEN 31
|
||||
|
||||
int main(void) {
|
||||
int lines;
|
||||
scanf("%d", &lines);
|
||||
|
||||
// Fancy way of allocating memory to 2d array
|
||||
char *arr[lines];
|
||||
for (int i = 0; i < lines; i++) {
|
||||
arr[i] = malloc(sizeof(char) * MAXLEN);
|
||||
}
|
||||
|
||||
// Populate the 2d array
|
||||
for (int i = 0; i < lines; i++) {
|
||||
scanf("%s", arr[i]);
|
||||
}
|
||||
|
||||
// Populate the order array
|
||||
int order[lines];
|
||||
for (int i = 0; i < lines; i++) {
|
||||
scanf("%d", &order[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < lines; i++) {
|
||||
printf("%s\n", arr[order[i]]);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue