uva 485 Pascal's Triangle of Death

题意:输出

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

1 7 21 35 35 21 7 1

知道出现10^60

总结:仍然是WA。单学会了很多关于double的处理方法,详细看注释

#include 
#include 
#include 
#include 
#include 
using namespace std;

int main()
{
    cout<<"1"< one;
    vector two;
    one.push_back(1);
    one.push_back(3);
    one.push_back(3);
    one.push_back(1);
    
    while(1){
        double one_size = one.size();
        two.push_back(1);
        cout<<"1";
        for(double i = 1;i<=one_size-1;i++){
            double temp = one[i-1]+one[i];
            //double temp_int = floor(temp);//可以输出【temp】取整
            if(temp >= 10e60){
                for(double i = 1;i


正确代码(转)

#include
#include
#include
using namespace std;

int dp[1500][150] = {0};

int main(){
  dp[0][0] = 1;
  int row = 1, digit;
  bool exit = 0;
  do{
    for( int i = row-2 ; i > 0 ; i-- ){
      for( int j = 0 ; j < 150 ; j++ ){
        dp[i][j] += dp[i-1][j];
        dp[i][j+1] += dp[i][j]/10;
        dp[i][j] %= 10;
      }
    }
    for( int i = 0 ; i < row ; i++ ){
      for( digit = 149 ; digit >= 0 ; digit-- )
        if( dp[i][digit] ) break;
      if( digit >= 60 ) exit = 1;

      for( ; digit >= 0 ; digit-- )
        printf( "%d", dp[i][digit] );

      if( i != row-1 ) printf( " " );
      else printf( "\n" );
    }
    dp[row++][0] = 1;
  } while( !exit );
  return 0;
}



你可能感兴趣的:(uva,看了别人的才有思路,多次wa,难题,大整数)