Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
581 B
0
Indexable
Never
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int a, b, len, negr, maxNegr,c;
    cin >> a;
	len = 0;
	maxNegr = 0;
	negr = 0;
	for (int i = 0; i < a; i++){
		cin >> b;
		if (b < 10) negr = b;
		else {
			for (int j = 0; j < b; j++) {
				if (b > pow(10, j) && b < pow(10, j + 1)) {
					len = j + 1;
					break;
				}
			}
			for (int j = 0; j < len; j++) {
				negr += int((b / pow(10, j))) % 10;
			}
		}
		if (negr > maxNegr) {
			maxNegr = negr;
			c = b;
		}
		negr = 0;
	}
	cout << c << ' ' << maxNegr;
	len = 0;
}