View Code of Problem 99

#include<stdio.h>
#include<math.h>
#include<string.h>

int main(void) {
	int m,n,s;
	int i,j;
	char str[1000];
	while(gets(str)) {
		if(strcmp(str,"0")==0) {
			break;
		}
		int kongge=0;
		for(i=0; i<strlen(str); i++) {
			if(str[i]==' ') {
				kongge++;
			}
		}

		if(kongge==0) {
			m=0;
			for(i=0; i<strlen(str); i++) {
				m=m*10+(str[i]-'0');
			}
			for(i=1; i<=m; i++) {
				if(i==1) {
					printf("%d",i);
				} else {
					printf(" %d",i);
				}
			}
			printf("\n");
		} else if(kongge==1) {
			m=0;
			n=0;
			int first=0;
			for(i=0; i<strlen(str); i++) {
				if(str[i]!=' '&&first==0) {
					m=m*10+(str[i]-'0');
				} else if(str[i]==' ') {
					first++;
				} else {
					n=n*10+(str[i]-'0');
				}
			}
			if(m>n) {
				for(i=m; i>=n; i--) {
					if(i==m) {
						printf("%d",i);
					} else {
						printf(" %d",i);
					}
				}
			} else {
				for(i=m; i<=n; i++) {
					if(i==m) {
						printf("%d",i);
					} else {
						printf(" %d",i);
					}
				}
			}
			printf("\n");

		} else {
			m=0;
			n=0;
			s=0;
			int first=0;
			for(i=0; i<strlen(str); i++) {
				if(str[i]!=' '&&first==0) {
					m=m*10+(str[i]-'0');
				} else if(str[i]==' ') {
					first++;
				} else if(str[i]!=' '&&first==1) {
					n=n*10+(str[i]-'0');
				} else {
					s=s*10+(str[i]-'0');
				}
			}
			if(m>n) {
				for(i=m; i>=n; i=i-s-1) {
					if(i==m) {
						printf("%d",i);
					} else {
						printf(" %d",i);
					}
				}
			} else {
				for(i=m; i<=n; i=i+s+1) {
					if(i==m) {
						printf("%d",i);
					} else {
						printf(" %d",i);
					}
				}
			}
			printf("\n");

		}
	}
}

Double click to view unformatted code.


Back to problem 99