Ronzii's Blog

Just your average geek's blog

Project Euler Problem 18,67

#include <iostream>
using namespace std;
int main ()
{
    int row;
    int array [102] [102];
    cin >> row;
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j <= i; j++)
            cin >> array [i] [j];
    }
    for( int i = row - 2; i >= 0; i--)
    {
        for(int j = 0; j <= i; j++ )
        {
            array[i][j]+=max( array[i + 1][j],array[i + 1][j + 1]);
        }
    }
    cout<<array[0][0];
    return 0;
}
Advertisements

March 26, 2012 Posted by | C++, Dynamic Programming | , , , , | Leave a comment

Project Euler Problem 6

#include <iostream>
using namespace std;
int main()
{
    unsigned long long sumSquare = 0,sum=0;
    for(int i=1;i<=100;i++)
    {
        sumSquare+= i*i;
        sum+=i;
    }
    sum*=sum;
    cout<<sum-sumSquare;
    return 0;
}

March 21, 2012 Posted by | C++ | , , | Leave a comment

Project Euler Problem 4

#include <iostream>
#include <climits>
using namespace std;
int reverse(int n)
{
    int result=0,remainder;
    while(n)
    {
        remainder = n%10;
        result = 10*result + remainder;
        n/=10;
    }
    return result;
}
int main()
{
    int maxValue = INT_MIN;
    for(int i=999;i>=100;i--)
    {
        for(int j=999;j>=100;j--)
        {
            int product = i*j;
            if(product==reverse(product))
            {
                maxValue = max(maxValue,product);
            }
        }
    }
    cout<<maxValue;
    return 0;
}

March 21, 2012 Posted by | C++ | , , | Leave a comment

Project Euler Problem 2

#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main()
{
    vector<int> v;
    int a =0,b=1,c;
    while(1)
    {
        if(a+b>4000000) break;
        c = a+b;
        a = b;
        b = c;
        if(c%2==0) v.push_back(c);
    }
    int sum = accumulate(v.begin(),v.end(),0);
    cout<<sum;
    return 0;
}

March 21, 2012 Posted by | C++ | , , , | Leave a comment

Project Euler Problem 1

#include <cstdio>
#include <iostream>
#include <list>
#include <numeric>
using namespace std;
int main()
{
    list<int> l;
    for(int i=0;i<1000;i++)
    {
        if(i%3==0) l.push_back(i);
        else if(i%5==0) l.push_back(i);
    }
    int sum = accumulate(l.begin(),l.end(),0);
    cout<<sum;
    return 0;
}

March 21, 2012 Posted by | C++ | , , , | Leave a comment