#include"stdafx.h"
#include<fstream>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
class Tosort {
public:
string s;
int Long;
Tosort(string s1,int Long1) {
s = s1;
Long = Long1;
}
};
typedef std::vector<std::string> StringList;
bool comp(Tosort a, Tosort b) {
if (a.Long < b.Long) {
return true;
}
else {
return false;
}
}
StringList splitstr(const std::string& str, char tag)
{
StringList li;
std::string subStr;
for (size_t i = 0; i < str.length(); i++)
{
if (tag == str[i])
{
if (!subStr.empty())
{
li.push_back(subStr);
subStr.clear();
}
}
else
{
subStr.push_back(str[i]);
}
}
if (!subStr.empty())
{
li.push_back(subStr);
}
return li;
}
int main() {
string s;
ifstream inf;
inf.open("C://Users//11865//Desktop//train.txt");
ofstream outf;
string trainTxt = "C:/Users/11865/Desktop/train2.txt";
outf.open(trainTxt, ios::out);
vector<Tosort> FTosort;
while (getline(inf, s))
{
vector<string> test;
test = splitstr(s, ' ');
string FileName = test[0];
vector<string> test2= splitstr(FileName, '_');
test2[3]= test2[3].substr(0, test2[3].length() - 4);
string usename = test2[3];
int Long = usename.length();
FTosort.push_back(Tosort(s,Long));
}
sort(FTosort.begin(), FTosort.end(), comp);
for (int i = 0; i < FTosort.size(); i++) {
cout << FTosort[i].s << endl;
outf << FTosort[i].s << endl;
}
inf.close();
outf.close();
return 0;
}