View Code of Problem 3497

#include<iostream>
using namespace std;
string c(string a,string b){
	if(a.size()<b.size())
	swap(a,b);
	while(a.size()!=b.size())
	b='0'+b;
	int f=0,l=a.size();
	while(l--){
		a[l]=a[l]+b[l]-'0'+f;
			if(a[l]-'0'>9){
				a[l]-=10;f=1;
			}
			else
			f=0;
	}
	if(f==1)
	a='1'+a;
	return a;
}
int main(){
	string x[103];
	while(cin>>x[1]>>x[2]>>x[3]){
		for(int i=4;i<=100;++i){
			x[i]=c(x[i-1],x[i-2]);
			x[i]=c(x[i],x[i-3]);
		}
		cout<<x[100]<<endl;
	}
}

Double click to view unformatted code.


Back to problem 3497