• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Задача 3

Infiniti_Inter May 23rd, 2019 (edited) 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top