View Code of Problem 99

#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	while(getline(cin,str) && str!="0"){
		string s=str;
		int t=0;
		string num="";
		int n[3];
		int k=0;
		s.push_back('$');
		while(true){
			int it=str.find(' ');
			if(it==str.npos){
				break;
			}
			else{
				t++;
				str.erase(it,1);
			}
		}
	for(int i=0;i<s.size();i++){
		if(isdigit(s[i])){
			num.push_back(s[i]);
		}
		else{
			n[k]=stoi(num);
			k++;
			num="";
		}
	}
	int l=n[2]+1;
	if(t==0){
		for(int i=1;i<=n[0];i++){
			if(i==n[0]){
				cout<<i;
			}
			else{
				cout<<i<<' ';
			}
		}
	}
	else if(t==1){
		if(n[0]>n[1]){
			for(int i=n[0];i>=n[1];i--){
				if(i==n[1]){
					cout<<i;
				}
				else{
					cout<<i<<' ';
				}
			}
		}
		else{
			for(int i=n[0];i<=n[1];i++){
				if(i==n[1]){
					cout<<i;
				}
				else{
					cout<<i<<' ';
				}
			}
		}
	}
	else if(t==2){
		if(n[0]>n[1]){
			cout<<n[0];
			for(int i=n[0]-l;i>=n[1];i-=l){
					cout<<' '<<i;
			}
		}
		else{
			cout<<n[0];
			for(int i=n[0]+l;i<=n[1];i+=l){
					cout<<' '<<i;
				}
			}
		}
	cout<<endl;
	}
}

Double click to view unformatted code.


Back to problem 99