View Code of Problem 99

#include<iostream>
#include<string>
using namespace std;
int main(void){
	string s;
	while(getline(cin,s)){
		if(s=="0") break;
		int j=0;
		int b[4]={0};
		for(int i=0;i<s.length();i++){
			if(s[i]==' ')
				j++;
			else
				b[j]=b[j]*10+s[i]-'0';
		}
		if(b[1]==0){
			for(int k=1;k<b[0];k++)
				cout<<k<<" ";
			cout<<b[0]<<endl;
		}else{
			int m=b[0],n=b[1],h=0;
			if(b[2]!=0) h=b[2];
			if(m>n){
				for(int k=m;k>=n;k=k-h-1){
					if(k!=m)
						cout<<" ";
					cout<<k;
				}
				cout<<endl;
			}else{
				for(int k=m;k<=n;k=k+h+1){
					if(k!=m)
						cout<<" ";
					cout<<k;
				}
				cout<<endl;
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 99