回答編集履歴

2

ソース修正

2019/10/06 07:34

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  for (int i = 'A'; i <= 'Z'; i++) {
52
52
 
53
- printf("%c= %d(%f%%)\n", i, cnt[i], (double)cnt[i] / sum * 100.0);
53
+ printf("%c= %3d(%8.3f%%)\n", i, cnt[i], (double)cnt[i] / sum * 100.0);
54
54
 
55
55
  }
56
56
 
@@ -66,67 +66,69 @@
66
66
 
67
67
  ```text
68
68
 
69
- usr ~/Project/test % ./a.out
69
+ usr ~/Project/test % ./a.out
70
70
 
71
- 123abcABC
71
+ So she was considering in her own mind (as well as she could, for the
72
72
 
73
- qwerty
73
+ day made her feel very sleepy and stupid), whether the pleasure of
74
74
 
75
- QWERTYU
75
+ making a daisy-chain would be worth the trouble of getting up and
76
76
 
77
-  ←ここでCtl-D
77
+ picking the daisies, when suddenly a White Rabbit with pink eyes ran
78
78
 
79
- A= 2(10.526316%)
79
+ close by her.
80
80
 
81
- B= 2(10.526316%)
81
+ A= 16( 7.111%)
82
82
 
83
- C= 2(10.526316%)
83
+ B= 5( 2.222%)
84
84
 
85
- D= 0(0.000000%)
85
+ C= 5( 2.222%)
86
86
 
87
- E= 2(10.526316%)
87
+ D= 13( 5.778%)
88
88
 
89
- F= 0(0.000000%)
89
+ E= 31( 13.778%)
90
90
 
91
- G= 0(0.000000%)
91
+ F= 4( 1.778%)
92
92
 
93
- H= 0(0.000000%)
93
+ G= 5( 2.222%)
94
94
 
95
- I= 0(0.000000%)
95
+ H= 16( 7.111%)
96
96
 
97
- J= 0(0.000000%)
97
+ I= 17( 7.556%)
98
98
 
99
- K= 0(0.000000%)
99
+ J= 0( 0.000%)
100
100
 
101
- L= 0(0.000000%)
101
+ K= 3( 1.333%)
102
102
 
103
- M= 0(0.000000%)
103
+ L= 10( 4.444%)
104
104
 
105
- N= 0(0.000000%)
105
+ M= 3( 1.333%)
106
106
 
107
- O= 0(0.000000%)
107
+ N= 15( 6.667%)
108
108
 
109
- P= 0(0.000000%)
109
+ O= 11( 4.889%)
110
110
 
111
- Q= 2(10.526316%)
111
+ P= 6( 2.667%)
112
112
 
113
- R= 2(10.526316%)
113
+ Q= 0( 0.000%)
114
114
 
115
- S= 0(0.000000%)
115
+ R= 12( 5.333%)
116
116
 
117
- T= 2(10.526316%)
117
+ S= 16( 7.111%)
118
118
 
119
- U= 1(5.263158%)
119
+ T= 13( 5.778%)
120
120
 
121
- V= 0(0.000000%)
121
+ U= 7( 3.111%)
122
122
 
123
- W= 2(10.526316%)
123
+ V= 1( 0.444%)
124
124
 
125
- X= 0(0.000000%)
125
+ W= 9( 4.000%)
126
126
 
127
- Y= 2(10.526316%)
127
+ X= 0( 0.000%)
128
128
 
129
+ Y= 7( 3.111%)
130
+
129
- Z= 0(0.000000%)
131
+ Z= 0( 0.000%)
130
132
 
131
133
  usr ~/Project/test %
132
134
 

1

ソース修正

2019/10/06 07:34

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -12,19 +12,21 @@
12
12
 
13
13
  //
14
14
 
15
- int cnt[128] = {0};
15
+ int cnt[128] = {0};
16
16
 
17
17
  char buf[256];
18
18
 
19
19
 
20
20
 
21
- while(fgets(buf,sizeof buf, stdin) != NULL){
21
+ while (fgets(buf, sizeof buf, stdin) != NULL) {
22
22
 
23
- for(size_t pos= 0; buf[pos] != '\0'; pos++ ){
23
+ for (size_t pos = 0; buf[pos] != '\0'; pos++) {
24
24
 
25
- int ch= buf[pos];
25
+ int ch = buf[pos];
26
26
 
27
- if(isalpha(ch)){
27
+ if (isalpha(ch)) {
28
+
29
+ ch = toupper(ch);
28
30
 
29
31
  cnt[ch]++;
30
32
 
@@ -36,11 +38,19 @@
36
38
 
37
39
  //
38
40
 
39
- for( int i= 'A'; i <= 'Z'; i++){
41
+ int sum = 0;
40
42
 
41
- int count= cnt[i] + cnt[i+'a'-'A'];
43
+ for (int i = 'A'; i <= 'Z'; i++) {
42
44
 
45
+ sum += cnt[i];
46
+
47
+ }
48
+
49
+ //
50
+
51
+ for (int i = 'A'; i <= 'Z'; i++) {
52
+
43
- printf("%c= %d\n",i,count);
53
+ printf("%c= %d(%f%%)\n", i, cnt[i], (double)cnt[i] / sum * 100.0);
44
54
 
45
55
  }
46
56
 
@@ -58,66 +68,68 @@
58
68
 
59
69
  usr ~/Project/test % ./a.out
60
70
 
61
- 12adec
71
+ 123abcABC
62
72
 
63
- saeKK
73
+ qwerty
64
74
 
65
- ABC
75
+ QWERTYU
66
76
 
67
- ←ここでctl-D
77
+  ←ここでCtl-D
68
78
 
69
- A= 3
79
+ A= 2(10.526316%)
70
80
 
71
- B= 1
81
+ B= 2(10.526316%)
72
82
 
73
- C= 2
83
+ C= 2(10.526316%)
74
84
 
75
- D= 1
85
+ D= 0(0.000000%)
76
86
 
77
- E= 2
87
+ E= 2(10.526316%)
78
88
 
79
- F= 0
89
+ F= 0(0.000000%)
80
90
 
81
- G= 0
91
+ G= 0(0.000000%)
82
92
 
83
- H= 0
93
+ H= 0(0.000000%)
84
94
 
85
- I= 0
95
+ I= 0(0.000000%)
86
96
 
87
- J= 0
97
+ J= 0(0.000000%)
88
98
 
89
- K= 2
99
+ K= 0(0.000000%)
90
100
 
91
- L= 0
101
+ L= 0(0.000000%)
92
102
 
93
- M= 0
103
+ M= 0(0.000000%)
94
104
 
95
- N= 0
105
+ N= 0(0.000000%)
96
106
 
97
- O= 0
107
+ O= 0(0.000000%)
98
108
 
99
- P= 0
109
+ P= 0(0.000000%)
100
110
 
101
- Q= 0
111
+ Q= 2(10.526316%)
102
112
 
103
- R= 0
113
+ R= 2(10.526316%)
104
114
 
105
- S= 1
115
+ S= 0(0.000000%)
106
116
 
107
- T= 0
117
+ T= 2(10.526316%)
108
118
 
109
- U= 0
119
+ U= 1(5.263158%)
110
120
 
111
- V= 0
121
+ V= 0(0.000000%)
112
122
 
113
- W= 0
123
+ W= 2(10.526316%)
114
124
 
115
- X= 0
125
+ X= 0(0.000000%)
116
126
 
117
- Y= 0
127
+ Y= 2(10.526316%)
118
128
 
119
- Z= 0
129
+ Z= 0(0.000000%)
120
130
 
121
131
  usr ~/Project/test %
122
132
 
133
+
134
+
123
135
  ```