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