Skip to content

Instantly share code, notes, and snippets.

Created April 25, 2010 18:36
Show Gist options
  • Select an option

  • Save anonymous/378610 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/378610 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int m, n;
int flag = 1;
vector<string> list;
while (cin >> m >> n && m && n) {
list.clear();
for (int i = m; i <= n; i++) {
if (i < 10) {
string tmp = "";
tmp += (char)(i + 48);
list.push_back(tmp);
} else {
int flag = 1;
char a = i / 10 + 48;
char b = i % 10 + 48;
for (int j = 0; j < list.size(); j++) {
if (list[j][list[j].size() - 1] == a) {
list[j].push_back(b);
flag = 0;
break;
} else if (list[j][0] == b) {
list[j].insert(0, 1, a);
flag = 0;
break;
}
}
if (flag) {
string tmp = "";
tmp += a;
tmp += b;
list.push_back(tmp);
}
}
}
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < list.size(); j++) {
if (i == j) {
continue;
} else {
if (list[i][list[i].size() - 1] == list[j][0]) {
list[i].resize(list[i].size() - 1);
list[i] += list[j];
list.erase(list.begin() + j);
} else if (list[j][list[j].size() - 1] == list[i][0]) {
list[j].resize(list[j].size() - 1);
list[j] += list[i];
list.erase(list.begin() + i);
}
}
}
}
for (int i = 0; i < list.size(); i++) {
cout << list[i];
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment