teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

ソース修正

2019/10/06 07:34

投稿

cateye
cateye

スコア6851

answer CHANGED
@@ -24,7 +24,7 @@
24
24
  }
25
25
  //
26
26
  for (int i = 'A'; i <= 'Z'; i++) {
27
- printf("%c= %d(%f%%)\n", i, cnt[i], (double)cnt[i] / sum * 100.0);
27
+ printf("%c= %3d(%8.3f%%)\n", i, cnt[i], (double)cnt[i] / sum * 100.0);
28
28
  }
29
29
  //
30
30
  return 0;
@@ -32,37 +32,38 @@
32
32
  ```
33
33
  結果
34
34
  ```text
35
- usr ~/Project/test % ./a.out
35
+ usr ~/Project/test % ./a.out
36
+ So she was considering in her own mind (as well as she could, for the
37
+ day made her feel very sleepy and stupid), whether the pleasure of
38
+ making a daisy-chain would be worth the trouble of getting up and
39
+ picking the daisies, when suddenly a White Rabbit with pink eyes ran
36
- 123abcABC
40
+ close by her.
37
- qwerty
38
- QWERTYU
39
-  ←ここでCtl-D
40
- A= 2(10.526316%)
41
+ A= 16( 7.111%)
41
- B= 2(10.526316%)
42
+ B= 5( 2.222%)
42
- C= 2(10.526316%)
43
+ C= 5( 2.222%)
43
- D= 0(0.000000%)
44
+ D= 13( 5.778%)
44
- E= 2(10.526316%)
45
+ E= 31( 13.778%)
45
- F= 0(0.000000%)
46
+ F= 4( 1.778%)
46
- G= 0(0.000000%)
47
+ G= 5( 2.222%)
47
- H= 0(0.000000%)
48
+ H= 16( 7.111%)
48
- I= 0(0.000000%)
49
+ I= 17( 7.556%)
49
- J= 0(0.000000%)
50
+ J= 0( 0.000%)
51
+ K= 3( 1.333%)
52
+ L= 10( 4.444%)
53
+ M= 3( 1.333%)
54
+ N= 15( 6.667%)
55
+ O= 11( 4.889%)
56
+ P= 6( 2.667%)
50
- K= 0(0.000000%)
57
+ Q= 0( 0.000%)
51
- L= 0(0.000000%)
52
- M= 0(0.000000%)
53
- N= 0(0.000000%)
54
- O= 0(0.000000%)
55
- P= 0(0.000000%)
56
- Q= 2(10.526316%)
57
- R= 2(10.526316%)
58
+ R= 12( 5.333%)
59
+ S= 16( 7.111%)
60
+ T= 13( 5.778%)
61
+ U= 7( 3.111%)
62
+ V= 1( 0.444%)
58
- S= 0(0.000000%)
63
+ W= 9( 4.000%)
59
- T= 2(10.526316%)
60
- U= 1(5.263158%)
61
- V= 0(0.000000%)
62
- W= 2(10.526316%)
63
- X= 0(0.000000%)
64
+ X= 0( 0.000%)
64
- Y= 2(10.526316%)
65
+ Y= 7( 3.111%)
65
- Z= 0(0.000000%)
66
+ Z= 0( 0.000%)
66
67
  usr ~/Project/test %
67
68
 
68
69
  ```

1

ソース修正

2019/10/06 07:34

投稿

cateye
cateye

スコア6851

answer CHANGED
@@ -5,58 +5,64 @@
5
5
  int main(void)
6
6
  {
7
7
  //
8
- int cnt[128] = {0};
8
+ int cnt[128] = {0};
9
9
  char buf[256];
10
10
 
11
- while(fgets(buf,sizeof buf, stdin) != NULL){
11
+ while (fgets(buf, sizeof buf, stdin) != NULL) {
12
- for(size_t pos= 0; buf[pos] != '\0'; pos++ ){
12
+ for (size_t pos = 0; buf[pos] != '\0'; pos++) {
13
- int ch= buf[pos];
13
+ int ch = buf[pos];
14
- if(isalpha(ch)){
14
+ if (isalpha(ch)) {
15
+ ch = toupper(ch);
15
16
  cnt[ch]++;
16
17
  }
17
18
  }
18
19
  }
19
20
  //
21
+ int sum = 0;
20
- for( int i= 'A'; i <= 'Z'; i++){
22
+ for (int i = 'A'; i <= 'Z'; i++) {
21
- int count= cnt[i] + cnt[i+'a'-'A'];
22
- printf("%c= %d\n",i,count);
23
+ sum += cnt[i];
23
24
  }
24
25
  //
26
+ for (int i = 'A'; i <= 'Z'; i++) {
27
+ printf("%c= %d(%f%%)\n", i, cnt[i], (double)cnt[i] / sum * 100.0);
28
+ }
29
+ //
25
30
  return 0;
26
31
  }
27
32
  ```
28
33
  結果
29
34
  ```text
30
35
  usr ~/Project/test % ./a.out
31
- 12adec
36
+ 123abcABC
32
- saeKK
37
+ qwerty
33
- ABC
38
+ QWERTYU
34
- ←ここでctl-D
39
+  ←ここでCtl-D
35
- A= 3
40
+ A= 2(10.526316%)
36
- B= 1
41
+ B= 2(10.526316%)
37
- C= 2
42
+ C= 2(10.526316%)
38
- D= 1
43
+ D= 0(0.000000%)
39
- E= 2
44
+ E= 2(10.526316%)
40
- F= 0
45
+ F= 0(0.000000%)
41
- G= 0
46
+ G= 0(0.000000%)
42
- H= 0
47
+ H= 0(0.000000%)
43
- I= 0
48
+ I= 0(0.000000%)
44
- J= 0
49
+ J= 0(0.000000%)
45
- K= 2
50
+ K= 0(0.000000%)
46
- L= 0
51
+ L= 0(0.000000%)
47
- M= 0
52
+ M= 0(0.000000%)
48
- N= 0
53
+ N= 0(0.000000%)
49
- O= 0
54
+ O= 0(0.000000%)
50
- P= 0
55
+ P= 0(0.000000%)
51
- Q= 0
56
+ Q= 2(10.526316%)
52
- R= 0
57
+ R= 2(10.526316%)
53
- S= 1
58
+ S= 0(0.000000%)
54
- T= 0
59
+ T= 2(10.526316%)
55
- U= 0
60
+ U= 1(5.263158%)
56
- V= 0
61
+ V= 0(0.000000%)
57
- W= 0
62
+ W= 2(10.526316%)
58
- X= 0
63
+ X= 0(0.000000%)
59
- Y= 0
64
+ Y= 2(10.526316%)
60
- Z= 0
65
+ Z= 0(0.000000%)
61
66
  usr ~/Project/test %
67
+
62
68
  ```