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;
    }

  • 相关阅读:
    JS之事件及冒泡
    DOM读取和修改内联样式
    dom查询与修改的一些常用方法
    js修改this指向的三种方法(call,bind,apply)
    JS原型概念
    JS创建对象
    JS的this(谁调用就指向谁)
    变量声明提前与函数声明提前
    JS对象创建
    正则应用之数据采集房屋网站信息
  • 原文地址:https://www.cnblogs.com/Vpygamalion/p/5559080.html
Copyright © 2011-2022 走看看