View Code of Problem 3497

#include <iostream>
#include <cstdio>
using namespace std;
string add(string a,string b){
	if(a.size()>b.size()){
		for(int i=0;i<a.size()-b.size();i++){
			b = '0' + b;
		}
	}
	else if(a.size()<b.size()){
		for(int i=0;i<b.size()-a.size();i++){
			a = '0' + a;
		}
	}
	int carry = 0;
	for(int i=a.size()-1;i>=0;i--){
		int current = carry + a[i] -'0' + b[i]  -'0';
		a[i] = current % 10 + '0';
		carry = current / 10;
	}
	if(carry != 0){
		a = '1' + a;
	}
	return a;
}
int main(){
	int x,y,z;
	string a,b,c;
//	while(scanf("%d%d%d",&x,&y,&z)!=EOF){
////		int n;
////		cin>>n;
//		a = x +'0';
//		b = y +'0';
//		c = z +'0';
//		for(int i=0;i<97;i++){
//			string s = add(add(a,b),c); 
//			a = b;
//			b = c;
//			c = s;
//		}
//		cout<<c;
//	}
	while(cin>>a>>b>>c){
		for(int i=0;i<97;i++){
			string s = add(add(a,b),c); 
			a = b;
			b = c;
			c = s;
		}
		cout<<c<<endl;
	}
}

Double click to view unformatted code.


Back to problem 3497