Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <iostream>

#include <vector>
#include <algorithm>
using namespace std;

int setFormatRange(int a, int b) {


int p = 1;
while (a % 10 != b % 10) {
p *= 10;
a /= 10;
b /= 10;
}
return p;
}

int main() {

int n, st = -1, j, t;
cin >> n;
for (j = 1; n;++j) {
cout << "Case " << j << "\n";
int k, x;
vector<int> v;
for (k = 0; k < n; ++k) {
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
v.push_back(0);
for (k = 0; k + 1 < v.size(); ++k)
if (st == -1) {
if (v[k] == v[k + 1] - 1) st = v[k];
else cout << v[k] << "\n";
}
else if (v[k] != v[k + 1] - 1) {
int p = setFormatRange(st, v[k]);
cout << st << "-" << v[k] % p << "\n";
st = -1;
}
cout << "\n\n";
cin >> n;
}

return 0;
}

You might also like