## 485 - Pascal's Triangle of Death

Moderator: Board moderators

alamgir kabir
New poster
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am
Thanks Jan.
I missed only the line "When any number in the triangle is exceeds or equals 10^60"
I calculate only less than 10^60 so I get WA

Code: Select all

``````code removed after acc
``````
Thanks again Jan.
Last edited by alamgir kabir on Sat Nov 24, 2007 3:38 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
The last line should be

Code: Select all

``1 204 20706 ...``
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

peterkwan
New poster
Posts: 16
Joined: Sun Oct 28, 2007 1:54 pm
Here is my code and got WA:

Code: Select all

``````#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

string calc_sum(string str1, string str2) {
string s1 = str1, s2 = str2;
if (str1.length() > str2.length()) {
for (int i = str2.length(); i < str1.length(); i++)
s2 = '0' + s2;
}
else {
for (int i = str1.length(); i < str2.length(); i++)
s1 = '0' + s1;
}
int carry=0, digit=0;
string sum = "";
for (int i=s1.length()-1; i>=0; i--) {
int a = s1[i]-'0';
int b = s2[i]-'0';
digit = (a+b+carry)%10;
carry = (a+b+carry)/10;
sum += (char)(digit+'0');
}
if (carry>0) sum += (char)(carry+'0');
reverse(sum.begin(), sum.end());
return sum;
}

main() {
bool end_cond = false;
int n = 1;
vector<string> v1, v2;

while (!end_cond) {
v2 = v1;
v1.clear();
v1.push_back("1");
cout << "1";
for (int i = 1; i < n-1; i++) {
string s = calc_sum(v2[i-1], v2[i]);
v1.push_back(s);
cout << " " << s;
if (s.length() > 60) end_cond = true;
}
if (n > 1) {
v1.push_back("1");
cout << " 1";
}
cout << endl;
n++;
}
cout << endl;
return 0;
}
``````
What is the problem with my code? Thanks.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:

Code: Select all

``````  // cout << endl;
return 0;``````
Hope it helps.

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Contact:

### Re: 485 WA........

OKK
Last edited by uvasarker on Thu Feb 21, 2013 7:39 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 485 WA........

Don't double post, don't post in the wrong thread.
Check input and AC output for thousands of problems on uDebug!