-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlphabeticstatistics.cpp
More file actions
53 lines (53 loc) · 1.24 KB
/
Alphabeticstatistics.cpp
File metadata and controls
53 lines (53 loc) · 1.24 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
int main()
{
vector<char> tp;
char ans='0';
ifstream read("test.txt");
while(!read.eof())
{
read>>ans;
tp.push_back(ans);
}
int op[91]={0};
double sum=0.0;
vector<char>::iterator iter;
for(iter=tp.begin();iter!=tp.end();iter++)
{
if((*iter)>=65&&(*iter)<=90)//small
{
op[(int)*iter]++;
sum++;
}
else if((*iter)>=97&&(*iter)<=122)// big -32
{
op[((int)*iter)-32]++;
sum++;
}
else if((*iter)==32)// 32 空格
{
op[(int)(*iter)]++;
}
else if((*iter)==46)//46 .
{
op[(int)(*iter)]++;
}
else if((*iter)==44)// ,
{
op[(int)(*iter)]++;
}
//sum++;
}
printf("空格的个数为:%d\n",op[32]);
printf("'.'的个数为:%d\n",op[46]);
printf("','的个数为:%d\n",op[44]);
for(int i=65;i<=90;i++)
{
cout<<(char)(i+32)<<"的个数为"<<op[i]<<'\t'<<"所占百分比为"<<((double)op[i])/((double)sum)<<'%'<<endl;
}
system("pause");
return 0;
}