no everything ac

This commit is contained in:
juan 2022-06-02 11:59:54 +08:00
parent 0cb114e030
commit 781b2a1c0b
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7
2 changed files with 70 additions and 72 deletions

View file

@ -1,8 +1,5 @@
#include <stdio.h> #include <stdio.h>
#define FILENAME dict.dic
#define BUFLEN 65535
void countChar(FILE *fp); void countChar(FILE *fp);
void countLines(FILE *fp); void countLines(FILE *fp);
void countCaps(FILE *fp); void countCaps(FILE *fp);
@ -13,21 +10,21 @@ int main(void) {
int op; int op;
scanf("%d", &op); scanf("%d", &op);
switch (op) { switch (op) {
case (1): { case (1): {
countChar(fp); countChar(fp);
break; break;
} }
case (2): { case (2): {
countLines(fp); countLines(fp);
break; break;
} }
case (3): { case (3): {
countCaps(fp); countCaps(fp);
break; break;
} }
default: { default: {
break; break;
} }
} }
fclose(fp); fclose(fp);
@ -37,7 +34,7 @@ int main(void) {
void countChar(FILE *fp) { void countChar(FILE *fp) {
int cap = 0, low = 0, digits = 0, others = 0; int cap = 0, low = 0, digits = 0, others = 0;
char buf; char buf;
while ((buf = fgetc(fp)) != EOF) { while ((buf = getc(fp)) != EOF) {
if (buf >= 'A' && buf <= 'Z') { if (buf >= 'A' && buf <= 'Z') {
cap++; cap++;
} else if (buf >= 'a' && buf <= 'z') { } else if (buf >= 'a' && buf <= 'z') {
@ -54,58 +51,59 @@ void countChar(FILE *fp) {
printf("digit: %d\n", digits); printf("digit: %d\n", digits);
printf("others: %d\n", others); printf("others: %d\n", others);
} }
void countLines(FILE *fp) { void countLines(FILE *fp) {
// Scan one line first
char buf;
int lines = 0; int lines = 0;
int maxlen, minlen; int linemax = 0;
int i; int linemin = 0;
char buf[BUFLEN]; int i = 0;
while ((buf = fgetc(fp)) != EOF) {
// Firstly read one line if (buf != '\n') {
fgets(buf, BUFLEN * sizeof(buf[0]), fp); i++;
lines++; } else {
for (i = 0; buf[i] != '\n'; i++) { if (lines == 0) {
} linemax = i;
maxlen = i; linemin = i;
minlen = i; } else {
if (i > linemax) {
while (fgets(buf, sizeof(buf), fp) != NULL) { linemax = i;
lines++; }
for (i = 0; buf[i] != '\n'; i++) { if (i < linemin) {
linemin = i;
}
}
lines++;
i = 0;
}
}
printf("Task2:\nline: %d\n%d characters in max line.\n%d characters in min "
"line.\n",
lines, linemax, linemin);
}
void countCaps(FILE *fp) {
int low[26] = {};
int cap[26] = {};
char buf;
while ((buf = fgetc(fp)) != EOF) {
if (buf >= 'a' && buf <= 'z') {
low[buf - 'a']++;
} else if (buf >= 'A' && buf <= 'Z') {
cap[buf - 'A']++;
} }
if (i > maxlen) {
maxlen = i;
}
if (i < minlen) {
minlen = i;
}
} }
printf("Task2:\n"); printf("Task3:\n");
printf("line: %d\n", lines); printf("CAPITAL:\n");
printf("%d characters in max line.\n", maxlen); for (int i = 0; i < 26; i++) {
printf("%d characters in min line.\n", minlen); printf("%c:%d\n", i + 'A', cap[i]);
} }
void countCaps(FILE *fp) {
char low[26] = {}; printf("LOWERCASE:\n");
char cap[26] = {}; for (int i = 0; i < 26; i++) {
printf("%c:%d\n", i + 'a', low[i]);
char buf; }
while ((buf = fgetc(fp)) != EOF) {
if (buf >= 'a' && buf <= 'z') {
low[buf - 'a']++;
} else if (buf >= 'A' && buf <= 'Z') {
cap[buf - 'A']++;
}
}
printf("Task3:\n");
printf("CAPITAL:\n");
for (int i = 0; i < 26; i++) {
printf("%c:%d\n", i + 'A', cap[i]);
}
printf("LOWERCASE:\n");
for (int i = 0; i < 26; i++) {
printf("%c:%d\n", i + 'a', low[i]);
}
} }

View file

@ -7,20 +7,20 @@ int main(void) {
int a; int a;
char b[16]; // bool char b[16]; // bool
double c; char c[4096];
char d[4096]; char d[4096];
int n; int n;
scanf("%d", &n); scanf("%d", &n);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
fscanf(fp, "%i%s%lf%s", &a, b, &c, d); fscanf(fp, "%i%s%s%s\n", &a, b, c, d);
} }
printf("%i\n", a); printf("%i\n", a);
printf("%s\n", b); printf("%s\n", b);
printf("%lf\n", c); printf("%s\n", c);
printf("%s\n", d); printf("%s", d);
return 0; return 0;
} }