1)내가 푼코드
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
freopen_s(new FILE*, "input.txt", "r", stdin);
int p;
int n;
int result = 1;
cin >> p >> n;
for (int i = 0; i < n; i++) {
result = p * 2;
string num = to_string(result);
reverse(num.begin(), num.end());
p = stoi(num);
}
string value = to_string(result);
reverse(value.begin(), value.end());
cout << value << "\n";
return 0;
}
2)콜바이 레퍼런스 사용해서 하기!
->연습하구싶었눈데 ㅎㅎ
#include <iostream>
#include <string>
using namespace std;
void toReverse(string& str) {
int len = str.length();
string temp;
for (int x = len - 1; x >= 0; x--) {
temp += str[x];
}
str = temp;
}
int main() {
freopen_s(new FILE*, "input.txt", "r", stdin);
int p;
int n;
cin >> p;
cin >> n;
for (int i = 0; i < n; i++) {
p = p * 2;
string str = to_string(p);
toReverse(str);
p = stoi(str);
}
cout << p << "\n";
return 0;
}
[출력]
8394