Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <map>
- using namespace std;
- ifstream fin("input.txt");
- ofstream out("output.txt");
- void solve(int cur, int & sum, int & cnt, int & ans)
- {
- int cSum = 0; int cCnt = 0;
- int n = cur;
- while (n)
- {
- cSum += n % 10;
- cCnt++;
- n /= 10;
- }
- if (cSum > sum || cSum == sum && cCnt < cnt)
- {
- sum = cSum;
- cnt = cCnt;
- ans = cur;
- }
- }
- int main()
- {
- int sum = 0;
- int cnt = 0;
- int ans = 0;
- int n; fin >> n;
- while (n--)
- {
- int cur; fin >> cur;
- solve(cur, sum, cnt, ans);
- }
- out << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement