Advertisement
MonsterScripter

CodinGame_2023_08_22__15_00_00__sum_not_1.c

Aug 22nd, 2023
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. /**
  7.     The sum of all numbers that are not 1 :
  8.  
  9.     Entrée
  10.     4
  11.     3
  12.     1 7 1
  13.     1 1 7
  14.     7 7 7
  15.  
  16.     Sortie
  17.     35
  18. */
  19.  
  20. int main()
  21. {
  22.     int c;
  23.     scanf("%d", &c);
  24.     int n;
  25.     scanf("%d", &n); fgetc(stdin);
  26.     int sum = 0;
  27.     for (int i = 0; i < n; i++) {
  28.         char row[257];
  29.         scanf("%[^\n]", row); fgetc(stdin);
  30.         for (int j = 0; j < strlen(row); j++) {
  31.             if (row[j] != '1' && row[j] != ' ') sum += (row[j] - '0');
  32.         }
  33.     }
  34.     printf("%d\n", sum);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement