/*
* File: Main. cpp
* Author: 88250 <DL88250@gmail.com>, http://blog.csdn.net/DL88250
*
* Created on May 13,200 8, PM
*/
# Include <iostream>
# Include <fstream>
# Include <algorithm>
# Include <vector>
# Include <time. h>
Using namespace STD;
/**
* Check the same record in a file.
*
* Every record in data file is a random serial, like the followings:
* // Data file
* 1902323484354370234844
* 1928473090393719374
*....
*/
Vector <string> records; // store the data records
Vector <vector <string> Statistics; // statistics
/**
* Read the records from the data file which named "data.txt" into memory,
* Using a list store them.
*/
Void readrecords (){
Cout <"Get starting read records..." <Endl;
Ifstream fin ("data.txt ");
If (! Fin ){
Cout <"cannot open input file! "<Endl;
Return;
}
String Aline;
While (Getline (FIN, Aline )){
Records. push_back (Aline );
}
Fin. Close ();
Cout <"The amount of records:" <records. Size () <Endl;
}
/**
* Display the data records in console.
* @ Param amount display amount, start from {@ link # records}'s beginning
*/
Void displayrecords (INT amount ){
If (amount <0 | amount> records. Size ()){
Cout <"the specified amount exceeds the data records" <
"Size! "<Endl;
}
Cout <"display:" <Endl;
For (INT I = 0; I <amount; I ++ ){
Cout <records. at (I) <Endl;
}
Cout <Endl;
}
/**
* Display the statistic results in console.
*/
Void displaystats (){
Cout <"Statistics:" <Endl;
Cout <"a amount of the same data records:" <statistics. Size () <Endl;
For (INT I = 0; I <statistics. Size (); I ++ ){
Vector <string> aequalities = statistics. at (I );
Cout <aequalities. At (0) <"occurs" <aequalities. Size () <Endl;
}
}
/*
Bool greater (string S1, string S2 ){
Return s1.compare (S2 );
}
*/
/**
* Check the same data records.
*/
Void checkthesame (){
Sort (records. Begin (), records. End (); // sort them
// Displayrecords (10 );
For (INT I = 0; I <records. Size ()-1; I ++ ){
String record1 = records. at (I );
String record2 = records. At (I + 1 );
If (record1 = record2 ){
Vector <string> equalities;
Equalities. push_back (record1 );
Equalities. push_back (record2 );
Statistics. push_back (equalities );
}
}
Displaystats ();
}
Int main (INT argc, char ** argv ){
Readrecords ();
Displayrecords (10 );
Checkthesame ();
Cout <"elapsed time:" <clock ()/clocks_per_sec <Endl;
Return (exit_success );
}