fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. typedef struct foo {
  7. int n;
  8. bool b;
  9. } foo_t;
  10.  
  11. int main(void) {
  12. char a[32768];
  13. scanf("%3s%*[^\n]", a);
  14. int N = strtol(a, NULL, 10);
  15. if ((N < 1) || (N > 100)) {
  16. return EXIT_FAILURE;
  17. }
  18. scanf("%32767[^\n]%*[^\n]", a);
  19. foo_t* A = (foo_t*)malloc(sizeof(foo_t) * N);
  20. char* delim = " ";
  21. char* token = strtok(a, delim);
  22. int A_i = strtol(token, NULL, 10);
  23. if ((A_i < 1) || (A_i > 100)) {
  24. return EXIT_FAILURE;
  25. } else {
  26. A[0].n = A_i;
  27. A[0].b = A_i % 2 == 0;
  28. }
  29. for (int i = 1; i < N; i++) {
  30. token = strtok(NULL, delim);
  31. A_i = strtol(token, NULL, 10);
  32. if ((A_i < 1) || (A_i > 100)) {
  33. return EXIT_FAILURE;
  34. } else {
  35. A[i].n = A_i;
  36. A[i].b = A_i % 2 == 0;
  37. }
  38. }
  39. for (int i = 0; i < N; i++) {
  40. if (A[i].b) {
  41. printf("%d ", A[i].n);
  42. }
  43. }
  44. puts("");
  45.  
  46. free(A);
  47. return EXIT_SUCCESS;
  48. }
  49.  
Runtime error #stdin #stdout 0s 5556KB
stdin
Standard input is empty
stdout
Standard output is empty