백준/문자열
2908: 상수 / C++
Koalitsiya
2023. 3. 8. 15:17
문제
풀이
문자열 2개를 받은 뒤 각 문자열을 뒤집은 후 비교해서 더 큰 수를 출력한다.
#include <iostream>
#include <string>
using namespace std;
int main() {
string s1, s2, tmp1, tmp2;
cin >> s1 >> s2;
for (int i = 0; i < s1.length(); i++)
tmp1 += s1[s1.length() - (i + 1)];
for (int i = 0; i < s2.length(); i++)
tmp2 += s2[s2.length() - (i + 1)];
if (stoi(tmp1) > stoi(tmp2)) cout << tmp1;
else cout << tmp2;
return 0;
}