Check for random sequence repeats [C + +]

Source: Internet
Author: User
/*
* File:Main.cpp
* author:88250 <dl88250@gmail.com> http://blog.csdn.net/DL88250
*
* Created on May, 2008, 6:25 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 being 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);
}


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.