add pset12, but 1-3 and 2-1 doesn't get full score

pta sucks
This commit is contained in:
juan 2021-12-05 12:16:06 +08:00
parent 4626b75d12
commit a5d49c0c3f
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7
5 changed files with 139 additions and 2 deletions

View file

@ -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];
}

View 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;
}

View 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;
}
}

View 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;
}

View 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;
}