-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5-6.cpp
More file actions
34 lines (33 loc) ยท 903 Bytes
/
Lab5-6.cpp
File metadata and controls
34 lines (33 loc) ยท 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// ํ๋ก๊ทธ๋๋ฐ๋ฉ 5์ฃผ
// Lab5-6 ์๋ฌธ TEXT ์ ์ํ๋ฒณ ๋น๋์ check
// input.txt ๋ฅผ ์
๋ ฅ์ผ๋ก ๋ฐ๊ณ , ์ํ๋ฒณ๋ค์ countํ์ฌ ๋ฑ์ฅํ๋ ํ๋ฅ ์ ํ์
// ์
๋ ฅ์ ๋(keyboard ์์๋ CTRL-Z) EOF๋ก ๊ฒ์ฌ๋ฅผ ํ๋ค.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void main()
{
char c;
int total = 0; // ์ ์ฒด ๋ฌธ์์
int alpha = 0; // ์ํ๋ฒณ ๋ฌธ์์
int blank = 0; // blank(space, tab, newline) ๋ฌธ์์
int digit = 0; // 0~9 ๋ฌธ์์
int special = 0; // ํน์๋ฌธ์ ์
int count[26] = { 0 };//์ํ๋ฒณ๋ณ๋ก count
while ((c = getchar()) != EOF) { //
// ์ํ๋ฒณ ์นด์ดํธ ๋ถ๋ถ
total++;
if (isalpha(c)) { // ์ํ๋ฒณ๋ง ๊ฒ์ฌ
alpha++;
count[toupper(c) - 'A']++;
}
}
printf("\n\n์ ์ฒด๋ฌธ์์=%d ์ํ๋ฒณ์=%d\n", total, alpha);
for (c = 'A'; c <= 'Z'; c++) {
// ํ๋ฉด๊ณผ ๊ฐ์ด ์ถ๋ ฅ
printf("%c:%3d (%5.2lf%%)\n", c, count[c - 'A'],
count[c - 'A'] * 100. / alpha);
}
printf("\n");
}