include iostream include fstream include cstdio include vector include

  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
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
int get_length (string a, string b)
{
int k=0;
if (a.size()>b.size())
{
k=a.size()-b.size();
a=a.substr(0, b.size());
}
else
{
k=b.size()-a.size();
b=b.substr(0, a.size());
}
for (int i=0; i<a.size(); i++)
{
if (a[i]!=b[i])
k++;
}
return k;
}
int main()
{
string str, word;
char c;
int k=0, n=0;
vector <string> v;
vector <string> res;
map <pair<string, string>, int> lengths;
map <string, string> words;
ifstream file;
file.open("/home/anya/test_lst.txt");
while (file.get(c))
{
if ((c=='\n') || (c==' ') || (c==',') || (c=='.'))
{
if(str.size())
{
v.push_back(str);
str.clear();
}
}
else
str+=c;
}
for (int i=0; i<v.size(); i++)
{
if (v[i].length()> 32)
v[i] = v[i].substr(0,32);
}
for (int i=0; i<v.size(); i++)
for (int j=0; j<v.size(); j++)
{
lengths[make_pair<string,string>(v[i], v[j])]=get_length(v[i], v[j]);
}
map <pair<string, string>, int>::iterator iter;
for (iter=lengths.begin(); iter!=lengths.end(); iter++)
{
int max=0;
if ((*iter).second > max)
max=(*iter).second;
}
for (iter=lengths.begin(); iter!=lengths.end(); iter++)
{
if ((*iter).second == max)
{
words.insert(make_pair((*iter).first.first, (*iter).first.second));
}
}
for (iter=lengths.begin(); iter!=lengths.end(); iter++)
{
cout << (*iter).first.first << " " << (*iter).first.second << " " << (*iter).second << endl;
}
}