Advertisement
Scratius

MINSumm

Jan 20th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int summa(char* str);
  4.  
  5. int main()
  6. {
  7.     int const size = 50;
  8.     char str[size] = " ";
  9.     char str1[size];
  10.     int k = 1000;
  11.     int i = 0;
  12.     while (str[0] != '\n') {
  13.         fgets(str, size, stdin);
  14.         if (summa(str) < k) {
  15.             k = summa(str);
  16.             while (str[i] != '\n') {
  17.                 str1[i] = str[i];
  18.                 i++;
  19.             }
  20.            
  21.             i = 0;
  22.         }
  23.  
  24.     }
  25.  
  26.     printf("%s", str1);
  27.     return 0;
  28. }
  29.  
  30. int summa(char* str) {
  31.     int i = 0;
  32.     int sum = 0;
  33.  
  34.     while (str[i]) {
  35.         if (str[i] >= '0' && str[i] <= '9') {
  36.            
  37.             sum = sum + str[i] - '0';
  38.         }
  39.         i++;
  40.     }
  41.     return sum;
  42.  
  43. }
  44.  
  45.  
  46. if (s[i] != ' ') {
  47.     count *= 10;
  48.     count += s[i] - '0';
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement