View Code of Problem 99

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	vector<int>vector;
	while (getline(cin, str) && str != "0") {
		vector.clear();
		int count = 1;
		for (int i = 0; i < str.size(); i++) {
			if (str[i] == ' ')count++;
		}
		while (str.find(" ") != -1) {
			string s = str.substr(0, str.find(" "));
			int n = stoi(s);
			vector.push_back(n);
			str.erase(0, str.find(" ") + 1);
		}
		string s = str.substr(0, str.find(" "));
		int n = stoi(s);
		vector.push_back(n);
		if (count == 1) {
			for (int i = 1; i < vector[0]; i++) {
				cout << i << " ";
			}
			cout << vector[0] << endl;
		}
		if (count == 2) {
			int n1 = vector[0];
			int n2 = vector[1];
			if (n1 <= n2) {
				for (int i = n1; i < n2; i++) {
					cout << i << " ";
				}
				cout << n2 << endl;
			}
			else {
				for (int i = n1; i > n2; i--) {
					cout << i << " ";
				}
				cout << n2 << endl;
			}
		}
		if (count == 3) {
			int n1 = vector[0];
			int n2 = vector[1];
			int d = vector[2];
			if (n1 <= n2) {
				for (int i = n1; i <= n2;) {
					cout << i ;
					i += d+1;
					if (i <= n2) {
						cout << " ";
					}
				}
				cout << endl;
				
			}
			else {
				for (int i = n1; i >= n2;) {
					cout << i;
					i -= d + 1;
					if (i >= n2) {
						cout << " ";
					}
				}
				cout << endl;
			}
		}
 
 
	}
 
	return 0;
}

Double click to view unformatted code.


Back to problem 99