Pagini recente » Cod sursa (job #759050) | Cod sursa (job #1372815) | Cod sursa (job #743361) | Cod sursa (job #1080570) | Cod sursa (job #882111)
Cod sursa(job #882111)
#include <fstream>
#include <cstring>
using namespace std;
char a[20005][25];
int save[20005],savemax[20005];
int main(){
int i,j,n,st = 0,cont = 1, maxi = 1;
char elcur;
ifstream fin("text3.in");
ofstream fout("text3.out");
while(fin >> a[++st]){}
fout<<st - 1;
fout<<"\n";
for(i = 1; i < st; ++i){
cont = 1;
save[cont] = i;
elcur = a[i][strlen(a[i]) - 1];
for(j = i + 1; j < st; ++j){
if(a[j][0] == elcur){
elcur = a[j][strlen(a[j]) - 1];
cont++;
save[cont] = j;
}
}
if(cont > maxi){
for(j = 1; j <= cont; ++j)
savemax[j] = save[j];
maxi = cont;
}
}
fout<<(st-1) - maxi;
fout<<"\n";
for(i = 1; i <= maxi; ++i){
for(j = 0; j < strlen(a[savemax[i]]); ++j)
fout<<a[savemax[i]][j];
fout<<"\n";
}
}