Pairs of objects: He Tiseng
Contribution ratio: 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[])//judgment Word
{
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)//determine if the word has occurred
{
if (nn>0)
for (int i = 0; I <nn; i++)
{
if (!strcmp (Danci, WORD[I].S))//appears
{
word[i].num++; +1
return-1;
}
}
}
int main ()
{
Char sentence[1000];//character array length to be large enough
Ifstream file ("D://a_tale_of_two_cities.txt");
Ofstream outfile ("D://result1.txt"); Read
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]! = ' + ')//Turn lowercase
{
if (sentence[num2] >= ' A ' &&sentence[num2] <= ' Z ')
SENTENCE[NUM2] = sentence[num2] + 32;
num2++;
}
const char *delim = "," "." "!"; Separator
Char *p,
*pnext = NULL;
int n = 0,//counter N, t initialization
t = 0;
p = strtok_s (sentence, Delim, &pnext); strtovk_s function separates strings by delimiter
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)//Output statistic results
{
cout<< word[t].s << ":" << word[t].num << ' \ n ';
outfile<< word[t].s << ":" << word[t].num << ' \ n ';
t++;
}
Outfile.close ();
return 0;
}
Fourth time assignment