Page 4 of 4

Posted: Fri Nov 23, 2007 5:20 pm
by alamgir kabir
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.

Posted: Fri Nov 23, 2007 9:00 pm
by Jan
The last line should be

Code: Select all

1 204 20706 ...
Hope it helps.

Posted: Sun Dec 16, 2007 8:17 am
by peterkwan
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.

Posted: Thu Dec 20, 2007 11:32 am
by Jan
Edit your code...

Code: Select all

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

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

Posted: Mon Feb 18, 2013 2:25 pm
by uvasarker
OKK

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

Posted: Tue Feb 19, 2013 10:28 pm
by brianfry713
Don't double post, don't post in the wrong thread.