#include <string.h> #include <algorithm> #include <iostream> using namespace std; int main() { string input; while (getline(cin, input)) { int n = 0, m = 0, s = 0, i; int firstSpace = input.find_first_of(' '); int lastSpace = input.find_last_of(' '); if (firstSpace == input.npos) { n = atoi(input.c_str()); if (!n) break; for (i = 1; i < n; i++) { cout << i << ' '; } cout << n << endl; } else if (firstSpace == lastSpace) { n = atoi(input.substr(0, firstSpace).c_str()); m = atoi(input.substr(firstSpace + 1, input.length()).c_str()); if (n > m) { for (i = n; i > m; i--) { cout << i << ' '; } } else { for (i = n; i < m; i++) { cout << i << ' '; } } cout << m << endl; } else if (firstSpace < lastSpace) { n = atoi(input.substr(0, firstSpace).c_str()); m = atoi(input.substr(firstSpace + 1, lastSpace).c_str()); s = atoi(input.substr(lastSpace + 1, input.length()).c_str()); s += 1; if (n > m) { for (i = n; i > m; i -= s) { if((i - s) > m) cout << i << ' '; else cout << i; } } else { for (i = n; i < m; i += s) { if((i + s) < m) cout << i << ' '; else cout << i; } } if (i == m) cout << " " << m << endl; else cout << endl; } } return 0; } |
Double click to view unformatted code.