• 作业4:结对编程—词频统计


    结对对象:石莉静  

    源程序:

    #include <iostream>
    #include <vector>
    #include <algorithm> 
    #include <string>
    #include <fstream>
    using namespace std;
    
    struct WORD
    {
        string word;
        int num;
    };
    
    vector<WORD> a;  //创建vector对象,a[]
    
    int&value(const string&s)
    {
        for(int i=0;i<a.size();i++)
            if(s==a[i].word)
                return a[i].num;
            WORD p;
            p.word=s;
            p.num=0;
            a.push_back(p);  //在数组a最后添加数据
            return a[a.size()-1].num;
    }
    
    int main()
    {
        string str;
        cout << "输入字符串:
    ";
        char c;
        while(c=cin.get())
        {
            if((c>='a' && c<='z') || (c>='A' && c<='Z') || c==' ' || c=='
    ')  
                str+=c;   //去除符号
            if(c=='
    ')
                break;
        }
    //输出去掉非英文字符的字符串
        
        
        for(int j=0;str[j]!='';j++)
        {
            if(str[j]>='A'&&str[j]<='Z')
            {
                str[j]+= 32;  //大写字母Ascll码+32转换为小写
            }
        }
     //输出转换为小写的字符串
    
        string buf;
        ofstream fout("D:123.txt");  //把转换好的字符串写入文件
        fout<<str;
        fout.close ();
        ifstream fin("D:123.txt");  //读出写入的字符串并排序
        cout<<"输入统计单词:";
        char m;
        cin>>m;  //待统计单词m
        int total=0;    
        if(!strcmp(p,m))
        {
            total++;
        }
        while(fin>>buf)
        {
            value(buf)++;
        }
        vector<WORD>::const_iterator p;  //迭代器访问元素
        for(p=a.begin();p!=a.end();++p)
            cout<<p->word<<":"<<p->num<<'
    ';    
        return 0;
    }

     

    通过两次结对作业,可以明显的感受到合作的乐趣,枯燥的时间两个人一起可以变得更加精彩,对于不懂得地方一边百度一边讨论自己的想法,积少成多,比一个人慢慢磨要有效率的多。花了将近三个小时,讨论了不少观点,交换了各自的想法,也有对别人的算法进行分析,受益匪浅。

  • 相关阅读:
    Building a flexiable renderer
    Indirect Illumination in mental ray
    我的心情
    Cellular Automata
    Subsurface Scattering in mental ray
    Shader Types in mental ray
    BSP Traversal
    我的渲染器终于达到了MR的速度
    How to handle displacement and motion blur
    说明
  • 原文地址:https://www.cnblogs.com/cchenhui/p/5335196.html
Copyright © 2020-2023  润新知