×

I can't find mistake in mine solution to SnAckDown Chef and voting best friend solution.

 0 here is my code #include using namespace std; int main() { int T = 0; int N = 0; int sum = 0; int tmp = 0; bool flag = false; int arr[100]; int arr1[100]; cin >> T; for (int i = 0; i < T; i++) { flag = false; sum = 0; cin >> N; for (int j = 0; j < N; j++) { cin >> arr[j]; //sum += tmp; //if (sum>N || tmp >= N) //{ // flag = true; //} } for (int a = 0; a < N; a++) { sum += arr[a]; if (arr[a] >= N) { flag = true; break; } if (sum > N) { flag = true; break; } } if (sum < N) flag = true; if (flag) { cout << -1 << "\n"; } else { int count1 = 0; for (int a = 0; a < N; a++) { for (int b = 0; b < N; b++) { if (b != a) { if (arr[b]>0) { arr[b]--; cout << b + 1<<"\t"; } } } /* if (arr[a] != 0 && a!=N-1) { cout << a + 2<<" "; } else if (arr[a] != 0 && a == N - 1) { cout << 1; }*/ } cout << "\n"; } } return 0; }  asked 24 May '15, 19:56 2★v4_adi 11●3●5●8 accept rate: 0%

 0 Your solution gives wrong answer for the test case : 1 5 0 0 2 1 2 Your code gives output : 3 4 5 3 5 Clearly, this is wrong since the 5th chef cannot vote himself. answered 24 May '15, 21:22 4★snk967 184●1●1●10 accept rate: 9%
 0 Your code will fail with the below test case: 1 7 2 1 1 0 0 0 3 answered 24 May '15, 21:28 61●1 accept rate: 66%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×42
×37

question asked: 24 May '15, 19:56

question was seen: 889 times

last updated: 24 May '15, 21:28