我的任務排序是排序,其中的數字排列,每行一個在下面的例子中一個大的文本文件(> 1GB):如何號碼大文本文件
1906885614
1069046615
1576929003
1690826360
1540261768
786870227
1737467783
295136587
685162468
這是我到目前爲止。
#include <iostream>
#include <map>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
ofstream filtered;
ofstream filtered1;
ifstream textfile ("sort_1.txt");
string text_input;
map<string, long int> map_data;
vector<string> sort_vec;
long int i;
if (textfile.is_open())
{
filtered.open("filtered_list.txt");
while(! textfile.eof())
{
getline (textfile, text_input);
map_data[text_input]++;
if (map_data[text_input] == 1)
{
filtered << text_input << '\n';
}
}
filtered.close();
textfile.close();
cout << "Filter Process Complete!" << endl;
map_data.clear();
}
else
cout << "Unable to Open file: " << endl;
ifstream textfile1 ("filtered_list.txt");
if (textfile1.is_open())
{
filtered1.open("Filtered_Sorted.txt");
while(! textfile1.eof())
{
getline (textfile1, text_input);
sort_vec.push_back(text_input);
}
sort(sort_vec.begin(), sort_vec.end());
for (i = 0; i < sort_vec.size(); i++)
filtered1 << sort_vec[i] << endl;
cout << "Sorting Process Complete!" << endl;
filtered1.close();
textfile1.close();
sort_vec.clear();
}
else
cout << "Unable to Open file: " << endl;
system("pause");
return 0;
}
不幸的是,有輸出似乎不正確。這是什麼樣子:
1000107620
1000112250
1000112712
1000113375
1000115080
100011777
和這樣的:
999513319
999515927
999526130
99952947
999531752
999533144
999537
它看起來像程序忽略最後一位數字,我不知道爲什麼會發生。
Pease正確地縮進代碼。 –
對不起,我只是編輯後:) –
它的排序(以字母數字順序) –