Professional Documents
Culture Documents
Test
Test
/* Creator: Joo Francisco Castanho SPOJ Problem Set (classical) 1. Life, the Universe, and Everything Problem code: TEST */ /* #include <stdio.h> int main(void) { int x; for(; scanf("%d",&x) > 0 && x != 42; printf("%d\n", x)); return 0; } */ #define NUM_SIZE_LIMIT 99 int main() { int flag = 1; int count_numbers = 0; int temp_num = 0; char *curr_input = malloc(sizeof(char) * NUM_SIZE_LIMIT); int list[NUM_SIZE_LIMIT]; int i; do{ scanf("%s", curr_input); if(strcmp(curr_input,"stop") == 0) { flag = 0; } else { if(count_numbers >= NUM_SIZE_LIMIT) return 0; temp_num = atoi(curr_input); if(temp_num != 0) { list[count_numbers] = temp_num; count_numbers++; } } }while(flag!=0); printf("Output:\n"); for(i = 0;i < count_numbers;i++) { if(list[i] != 42) { printf("%d\n", list[i]); }