zoukankan      html  css  js  c++  java
  • 第四次作业

    结对对象:何季生

    贡献比例:50%;50%

    #include "stdafx.h"
    #include<iostream>
    #include<fstream>
    #include<cstring>
    using namespace std;

    struct Num{
    int num = 1;
    char *s = NULL;
    };

    Num word[99];

    int Judge(char danci[])//判断单词
    {
    bool j1 = (strlen(danci) >= 4);
    bool j2 = (danci[0] >= 'a' && danci[0] <= 'z');
    if (!(j1&&j2))
    return -1;
    else
    for (int ns = 1; danci[ns] != '';)
    {
    if (!((danci[ns] >= 'a' && danci[ns] <= 'z') || (danci[ns] >= '0' && danci[ns] <= '9')))
    return -1;
    else
    ns++;
    }
    }
    int Sta(char danci[], int nn) //判断该单词是否出现过
    {
    if (nn>0)
    for (int i = 0; i <nn; i++)
    {
    if (!strcmp(danci, word[i].s)) //出现
    {
    word[i].num++; //+1
    return -1;
    }
    }
    }
    int main()
    {
    char sentence[1000];//字符数组长度要足够大
    ifstream file("d://A_Tale_of_Two_Cities.txt");
    ofstream outfile("d://Result1.txt"); //读取
    if (!file){
    cout << "Unable to open file";
    exit(1);
    }
    if (!outfile){
    cout << "Unable to open outmyfile";
    exit(1);
    }
    while (!file.eof())
    {
    file.getline(sentence, 1000);
    }
    file.close();
    int num2 = 0;
    while (sentence[num2] != '')//转小写
    {
    if (sentence[num2] >= 'A'&&sentence[num2] <= 'Z')
    sentence[num2] = sentence[num2] + 32;
    num2++;
    }
    const char *delim = " ,“”.''‘’!?"; //分隔符
    char *p,
    *pNext = NULL;
    int n = 0, //计数器 n ,t 初始化
    t = 0;
    p = strtok_s(sentence, delim, &pNext); //strtovk_s函数根据分隔符分隔字符串
    while (p)
    {
    if (Judge(p) != -1)
    {
    if (Sta(p, n) != -1)
    {
    word[n].s = p;
    n++;
    }
    }
    p = strtok_s(NULL, delim, &pNext);
    }

    while (word[t].s) //输出统计结果
    {
    cout<< word[t].s << ":" << word[t].num << ' ';
    outfile<< word[t].s << ":" << word[t].num << ' ';
    t++;
    }
    outfile.close();
    return 0;
    }

  • 相关阅读:
    最新国家标准下载(2020-7-31)
    SL/T 264-2020 水利水电工程岩石试验规程
    SH/T 3082-2019 石油化工仪表供电设计规范
    GB/T 4780-2020 汽车车身术语
    Java——冒泡排序
    JSP处理XML数据
    JSP标准标签库(JSTL)
    千锤百炼软工第十九天
    千锤百炼软工第十八天
    千锤百炼软工第十七天
  • 原文地址:https://www.cnblogs.com/Vpygamalion/p/5559080.html
Copyright © 2011-2022 走看看