http://abc045.contest.atcoder.jp/tasks/arc061_a
というプログラミング練習サイトのこの問題をやっていて、全数探索のプログラムで、文字列が10,9を超える時実行時エラーになってしまいます。原因がよくわからないのでエラーの原因がわかりそうな方がいたら教えてください。
#include <iostream> #include <cmath> #include <ctime> #include <algorithm> #include <stdio.h> #include <string> #include <string.h> #include <stdlib.h> #include <sstream> #include <vector> #include <map> #include <fstream> using namespace std; typedef long long int ll; const int N = 100; void dfs(int n, int x, string str); ll sum = 0; string S; bool Visit[N]; int main() { cin >> S; int len = S.length(); dfs(len, 0, S); sum += stoi(S); cout << sum << endl; return 0; } void dfs(int n, int x, string str) { string S2 = ""; if (x > 0) { for (int i = 0; i < n; i++) { S2 += str[i]; if (Visit[i]) { cout << S2 << " "; sum += stoi(S2); S2 = ""; } } if (S2.length() > 0) { cout << S2 << endl; sum += stoi(S2); } } if (x >= n) { return; } else { for (int i = x; i < n - 1; i++) { if (!Visit[i]) { Visit[i] = true; dfs(n, x + 1, str); Visit[i] = false; } } } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/03 03:29
2016/10/03 03:40