Looking for the water king 2--to find three of the Aqua Kings

Source: Internet
Author: User

First, the experimental topic

Second, the realization method and the design idea

Third, the experimental code

//data:2016.5.27#include <iostream>#include<string>#include<fstream>using namespacestd;voidGetArray (stringa[]) {    stringstrtemp;//gets the first character in the file to determine if the file is emptycout <<"To read a list of posts, you can:"<<Endl;    FStream Filein; Filein.open ("ID.txt"Ios::inch);//Read List of posts from file ID.txt    if(!filein.is_open ())//determine if the file is open{cout<<"no file opened!! "<<Endl; Exit (0); } Filein>> strtemp;//This punctuation the first character in the file and must be in conjunction with the following judgment    if(Filein.eof ())//Determine If the open file is empty and be aware of the condition{cout<<"Open the file is empty!! "<<Endl; Exit (0); } a[0] = strtemp;//open file is not empty, read into the contents of the filecout << strtemp <<Endl;  for(inti =1; I < -; i++) {Filein>>A[i]; cout<< A[i] <<Endl; } filein.close ();}voidGetwaterring (stringstritem[]) {    intintcount[3] = {0,0,0};//set three variables to count the number of occurrences of the record ID number    stringstrid[3] = {"#","#","#"};//set three variables to record the ID number//here's how to find Three Kings     for(inti =0; I < -; i++)    {        if(strid[0] ==Stritem[i]) {intcount[0] = intcount[0] +1; }        Else if(strid[1] ==Stritem[i]) {intcount[1] = intcount[1] +1; }        Else if(strid[2] ==Stritem[i]) {intcount[2] = intcount[2] +1; }        Else if(intcount[0] ==0) {intcount[0] =1; strid[0] =Stritem[i]; }        Else if(intcount[1] ==0) {intcount[1] =1; strid[1] =Stritem[i]; }        Else if(intcount[2] ==0) {intcount[2] =1; strid[2] =Stritem[i]; }        Else{intcount[0] = intcount[0] -1; intcount[1] = intcount[1] -1; intcount[2] = intcount[2] -1; }} cout<<"The first water king is:"<< strid[0] <<Endl; cout<<"the second king of water is:"<< strid[1] <<Endl; cout<<"A third water king is:"<< strid[2] <<Endl;}intMain () {stringstritem[ -];//sets an array to record the ID number of each post, which can be used without initialization and error if initialized to nullGetArray (stritem);    Getwaterring (stritem); return 0;}

Four, the experiment

Five, experimental experience

Looking for the water king 2--to find three of the Aqua Kings

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.