1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Item
{
int sesion;
int corrida;
int secuencias;
string deletrear;
};
bool sortBy( const Item &a, const Item &b )
{
if ( a.sesion < b.sesion ) return true;
if ( a.sesion > b.sesion ) return false;
return a.corrida < b.corrida;
}
int main()
{
// ofstream out( "output.dat" );
ostream &out = cout;
// ifstream in( "input.dat" );
istringstream in( "Sesión 1 (COPY MODE): \n"
"Número de secuencias: 15 \n"
" \n"
"CORRIDA 1: \n"
"CARACTERES A DELETREAR : CALOR \n"
" \n"
"CORRIDA 2: \n"
"CARACTERES A DELETREAR : CARINO \n"
" \n"
"CORRIDA 3: \n"
"CARACTERES A DELETREAR : SUSHI \n"
" \n"
"Sesión 2 (COPY MODE): \n"
"CORRIDA 1: \n"
"Número de secuencias: 15 \n"
" \n"
"CARACTERES A DELETREAR: SUSHI \n"
"CARACTERES RECONOCIDOS: SUSHI \n"
" \n"
"Sesión 3 (ONLINE FREE MODE): \n"
"Número de secuencias: 15 \n"
" \n"
"CORRIDA 1: \n"
" \n"
"CARACTERES A DELETREAR: CENAR \n"
"CARACTERES RECONOCIDOS: CENAR \n"
" \n"
"CORRIDA 2: \n"
" \n"
"CARACTERES A DELETREAR: COLOR \n"
"CARACTERES RECONOCIDOS: COLOR \n"
" \n"
"CORRIDA 3: \n"
" \n"
"CARACTERES A DELETREAR: DULCES \n"
"CARACTERES RECONOCIDOS: DULCES \n" );
int sesion = 0, secuencias = 0, corrida = 0;
string deletrear, line, dummy;
vector<Item> items;
while ( getline( in, line ) )
{
if ( line.find( "Sesión" ) != string::npos )
{
stringstream ss( line );
ss >> dummy >> sesion;
}
else if ( line.find( "secuencias" ) != string::npos )
{
stringstream ss( line );
getline( ss, line, ':' );
ss >> secuencias;
}
else if ( line.find( "CORRIDA" ) != string::npos )
{
stringstream ss( line );
ss >> dummy >> corrida;
}
else if ( line.find( "DELETREAR" ) != string::npos )
{
stringstream ss( line );
getline( ss, line, ':' );
ss >> deletrear;
items.push_back( { sesion, corrida, secuencias, deletrear } );
}
}
sort( items.begin(), items.end(), sortBy );
for ( const auto &e : items ) out << e.sesion << '\t' << e.corrida << '\t' << e.secuencias << '\t' << e.deletrear << '\n';
}
| |