Advertisement
Infiniti_Inter

Задача 3

May 23rd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <map>
  6. using namespace std;
  7.  
  8.  
  9.  
  10. ifstream fin("input.txt");
  11. ofstream out("output.txt");
  12.  
  13.  
  14. void solve(int cur, int & sum, int & cnt, int & ans)
  15. {
  16.     int cSum = 0; int cCnt = 0;
  17.     int n = cur;
  18.     while (n)
  19.     {
  20.         cSum += n % 10;
  21.         cCnt++;
  22.         n /= 10;
  23.     }
  24.     if (cSum > sum || cSum == sum && cCnt < cnt)
  25.     {
  26.         sum = cSum;
  27.         cnt = cCnt;
  28.         ans = cur;
  29.     }
  30. }
  31.  
  32. int main()
  33. {
  34.     int sum = 0;
  35.     int cnt = 0;
  36.     int ans = 0;
  37.     int n; fin >> n;
  38.     while (n--)
  39.     {
  40.         int cur; fin >> cur;
  41.         solve(cur, sum, cnt, ans);
  42.     }
  43.     out << ans;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement