Fourth time assignment

Source: Internet
Author: User

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&AMP;&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.