Created by
Willy Pillow
last modified
| #include <iostream>
int atoi(char const *str) {
int n = 0;
while (*str != '\0') {
if (!isdigit(*str)) return -1;
n = n * 10 + *str++ - '0';
}
return n;
}
int main() {
char strs[5000][100];
int len = 0, realI = 1;
while (std::cin >> strs[len++]);
for (int i = 0; i < len && realI <= 2500; i++) {
if (atoi(strs[i]) != realI) {
int j = i;
while (atoi(strs[j]) + 1 != atoi(strs[j + 1]) || atoi(strs[j]) <= realI) j++;
std::cout << realI << ", ";
for (int k = i; k < j; k++) std::cout << strs[k] << ' ';
std::cout << "->";
for (int k = realI; k < atoi(strs[j]); k++) std::cout << k << ' ';
std::cout << '\n';
i = j;
realI = atoi(strs[j]);
}
realI++;
}
}
|
| #include <iostream>
#include <cstring>
int getInt(char *str) {
char *end;
if (!(std::cin >> str)) return -1;
int in = strtol(str, &end, 10);
if (*end != '\0') return 0;
return in;
}
int main() {
int in;
char str[100];
for (int i = 0, realI = 1; (in = getInt(str)) != -1; i++, realI++) {
if (in != realI) {
char err[100], replace[100] = "";
strcpy(err, str);
int j, newIn, lastIn = in;
for (j = i + 1;; j++) {
newIn = getInt(str);
if ((unsigned)(newIn - realI - 1) < 5u || lastIn == newIn - 1) break;
sprintf(err + strlen(err), " %s", str);
lastIn = newIn;
}
for (int k = realI; k < newIn; k++) sprintf(replace + strlen(replace), " %d", k);
std::cout << realI << ", " << err << "->" << replace << '\n';
i = j;
realI = newIn;
}
}
}
|
| #include <iostream>
#include <cstring>
int getInt(char *str) {
char *end;
if (!(std::cin >> str)) return -1;
int in = strtol(str, &end, 10);
if (*end != '\0') return 0;
return in;
}
int main() {
int in;
char str[100];
for (int i = 0, realI = 1; (in = getInt(str)) != -1; i++, realI++) {
if (in != realI) {
char err[100], replace[100] = "";
sprintf(err, " %s", str);
int j, newIn, lastIn = in, add = 0;
for (j = i + 1;; j++) {
newIn = getInt(str);
if ((unsigned)(newIn - realI - 1) < 5u || lastIn == newIn - 1) break;
sprintf(err + strlen(err), " %s", str);
lastIn = newIn;
}
if (lastIn == newIn - 1 && realI < newIn) {
for (int k = strlen(err) - 1; err[k] != ' '; k--) err[k] = '\0';
newIn--;
add = 1;
}
for (int k = realI; k < newIn; k++) sprintf(replace + strlen(replace), " %d", k);
std::cout << realI << "," << err << "->" << replace << '\n';
i = j;
realI = newIn + add;
}
}
}
|