Created
August 6, 2012 09:37
-
-
Save srinathgs/3272742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| int main() | |
| { | |
| vector<int> digits; | |
| int carry; | |
| digits.push_back(1); | |
| //Just Old School Multiplication. | |
| for(int i = 1;i<=1000;i++){ | |
| carry = 0; | |
| for(vector<int>::iterator i = digits.begin();i != digits.end();i++){ | |
| *i = *i*2 + carry; | |
| if(*i > (9) && ((i+1)!= digits.end())){ | |
| *i = *i - 10; | |
| carry = 1; | |
| } | |
| else if(*i>(9) && ((i+1)==digits.end())){ | |
| *i = *i - 10; | |
| digits.push_back(1); | |
| break; | |
| } | |
| else if(*i<=9){ | |
| carry = 0; | |
| } | |
| } | |
| } | |
| int sum = 0; | |
| for(vector<int>::iterator j = digits.begin(); j!=digits.end();j++){ | |
| sum+=*j; | |
| } | |
| cout<<sum<<endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment