#include<iostream> #include<vector> #include<algorithm> #include<string> #include<climits> #include<cmath> #include<unordered_map> #include<set> using namespace std; int main() { string str; while (getline(cin, str)) { if (str == "0") break; if (str.find(' ') == str.npos) { int num = atoi(str.c_str()); for (int i = 1; i <= num; i++) { cout << i; if (i != num) cout << " "; } } else if (count(str.begin(), str.end(), ' ') == 1) { int pos = str.find(' '); int begin = atoi((str.substr(0, pos)).c_str()); int end = atoi((str.substr(pos + 1, str.size() - pos - 1).c_str())); if (begin > end) { for (int i = begin; i >= end; i--) { cout << i; if (i != end) cout << " "; } } else { for (int i = begin; i <= end; i++) { cout << i; if (i != end) cout << " "; } } } else { int pos1 = str.find(' '); int pos2 = str.find(' ', pos1 + 1); int begin = atoi((str.substr(0, pos1)).c_str()); int end = atoi((str.substr(pos1 + 1, pos2 - pos1 - 1).c_str())); int step = atoi((str.substr(pos2 + 1, str.size() - pos2 - 1).c_str())); if (begin > end) { for (int i = begin; i >= end; i -= (step + 1)) { if (i != begin) cout << " "; cout << i; } } else { for (int i = begin; i <= end; i += (step + 1)) { if (i != begin) cout << " "; cout << i; } } } cout << endl; } } |
Double click to view unformatted code.