View Code of Problem 99

#include<bits/stdc++.h>
int main(){
	int a[1001];
	int k,t,t1;
	char ch;
	while(~scanf("%d",&a[0])){
		if(a[0]==0)
			break;
		int k=1;int count=1;
		while(ch=getchar()!='\n'){
			scanf("%d",&a[k]);
			k++;
			count++;
		}
		if(count==1){
			for(int i=1;i<a[0];i++)
				printf("%d ",i);
				printf("%d\n",a[0]);
		}
		else if(count==2){
			if(a[0]>a[1]){
				for(int i=a[0];i>a[1];i--)
					printf("%d ",i);
					printf("%d\n",a[1]);
			}
			else{
				for(int i=a[0];i<a[1];i++)
					printf("%d ",i);
					printf("%d\n",a[1]);
			}
		}
		else if(count==3){
			if(a[1]>a[0]){
				t=a[0];
				while(1){
					if(t+a[2]+1>a[1])
						break;
					printf("%d ",t);
					t=t+a[2]+1;
				}
					printf("%d\n",t);
			}
			else{
				t=a[0];
				while(1){
					if(t-a[2]-1<a[1])
						break;
					printf("%d ",t);
					t=t-a[2]-1;
				}
				printf("%d\n",t);
			}
		}		
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 99