功能1 小文件输入,为表明程序能跑,结果真实而不是迫害老五,请他亲自键盘在控制台下输入命令。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 4 #include<fstream>
 5 #include<string>
 6 #include<map>
 7 #include <iomanip>
 8 using namespace std;
 9 int main()
10 {
11     FILE *fp;
12     char text[1024];
13     char s[100];
14     //gets(s);
15     printf(">type test.txt\n");
16     fp=fopen("d:\\test.txt","r");
17     //fp=fopen(s,"r");
18     int n=0;
19     int i;
20     map<string,int>my_map;
21     while(fgets(text,1024,fp)!=NULL)
22     {
23         puts(text);
24         i=0;
25         while(text[i]!='\0')
26         {
27             char s[30];
28             int j=0;
29             while((text[i]>='a'&&text[i]<='z')||(text[i]>='A'&&text[i]<='Z'))
30             {
31                 if(text[i]>='A'&&text[i]<='Z')
32                 text[i]+='a'-'A';
33                 s[j++]=text[i++];  
34             }
35             s[j]='\0';
36             if(my_map[s]==0)
37             n++;
38             my_map[s]++;
39             if(text[i]=='\0') break;
40             else
41             i++;
42         }
43          
44     }
45     fclose(fp);
46     map<string,int>::iterator it;
47     printf("\n\n");
48     printf(">wf  -s  test.txt\n");
49     cout<<"total"<<"  "<<n-1<<endl<<endl<<endl;
50     for(it=my_map.begin(),i=1;it!=my_map.end();it++,i++)
51     {
52         if(it->first=="")
53         continue;
54         cout<<left;
55         cout<<setw(10)<<it->first;
56         cout<<setw(10)<<it->second;
57         cout<<"                                                            ";
58         if(i%8==0) 
59       //  cout<<'\n';
60       printf("\n");
61     }
62     cout<<'\n';  
63     return 0;
64 }
View Code

相关文章:

  • 2021-05-28
猜你喜欢
  • 2021-12-15
相关资源
相似解决方案