• 读取英文文档,找出出现次数前十的单词


    #include<iostream> #include<fstream> #include<string> #define MAX 32 using namespace std; struct word { char name[MAX]; int num; struct word *next; }; void read(struct word*&head) {     ifstream infile("test.txt");     infile>>noskipws;     if(!infile){   cout<<"can not open!"<<endl;   return;  }     char a,temp[MAX];     struct word *p;     while(infile)     {         int i=0;            infile.get(a);         temp[0]=' ';         while((a>='a'&&a<='z')||(a>='A'&&a<='Z')||temp[0]==' ')         {             if(a>='a'&&a<='z'||a>='A'&&a<='Z')             {                 temp[i]=a;                 i++;             }             infile.get(a);             if(infile.eof())     break;         }         temp[i]='';         p=head->next;            while(p)         {             if(!_stricmp(temp,p->name)){     p->num++;     break;    }             p=p->next;         }         if(!p&&temp[0]!='')         {                 p=new word;                 strcpy(p->name,temp);                 p->num=1;                 p->next=head->next;                 head->next=p;         }     }     infile.close(); } void out(struct word*head,int n) {     struct word *p;     p=head->next;     for(int i=0;i<n;i++)     {         cout<<"单词:"<<p->name<<"   出现的次数:"<<p->num<<endl;         p=p->next;     } } void output(struct word*&head) { ofstream output("out.txt"); struct word *p; p=head->next; while(p)     {         output<<"单词"<<p->name<<"   出现的次数"<<p->num<<endl;         p=p->next;     }

    }

    void sort(struct word*&head) {     struct word *p,*q,*s,*l;     q=head;     p=head->next;     s=p->next;     p->next=NULL;     while(s)     {         while(p&&p->num>s->num)         {             q=p;             p=p->next;         }         q->next=s;         l=s->next;         s->next=p;         s=l;         p=head->next;         q=head;     } } void main() { struct word *head; head=new word; head->next=NULL; read(head); sort(head); out(head,10); output(head); }

    文档:

       Many of the women who have joined the American workforce since the 1970s have the computer revolution to thank, according to a new study.
      A researcher, Dr Weinberg at Ohio State University, estimated that increased computer use in the workplace explains about 55 percent of the increase in the demand for women workers since the mid-1970s. Many of the new jobs are in blue-collar industries.
      “Computers have opened up a lot of job opportunities for women that weren’t available before,” said Bruce Weinberg, author of the study and assistant professor of economics at Ohio State University.

  • 相关阅读:
    HTML5项目笔记7:使用HTML5 WebStorage API构建与.NET对应的会话机制 Hello
    论设计模式和分析模式
    昨天我做了点什么事情啊?
    时间,时间,还是时间
    人生需要规划
    突然想起今天的博客汇报没写
    昨天看了熊猫大侠
    双休日往往会忘了写日志
    老婆说我是缺心眼!
    要下班了才想起没写报告
  • 原文地址:https://www.cnblogs.com/weiailian/p/3578162.html
Copyright © 2020-2023  润新知