Problem link
https://atcoder.jp/contests/arc061/tasks/arc061_a
Problem Summary
문자열 s의 문자 사이에 + 를 넣어 만들 수 있는 수를 전부 더하는 문제.
Solution
그냥 말 그대로 +를 문자 사이에 다 한 번 씩 넣어서 만들 수 있는 수를 더하면 된다.
비트 연산으로 간단하게 가능.
Source Code
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
long long ans = 0;
for (int i = 0; i < (1 << (s.length() - 1)); i++)
{
long long num = 0;
for (int j = 0; j < s.length(); j++)
{
num *= 10;
num += s[j] - '0';
if ((1 << j) & i)
{
ans += num;
num = 0;
}
}
ans += num;
}
cout << ans << endl;
}