## 10334 - Ray Through Glasses

Moderator: Board moderators

dispanser
New poster
Posts: 18
Joined: Wed May 01, 2002 4:12 pm
Location: Jena/Germany
Contact:
Accepted ankur_vjy
New poster
Posts: 2
Joined: Thu Jan 24, 2008 8:51 pm

### Re: 10334 - Ray Through Glasses

i cross checked some of the input cases and they seem to work.
I m implementing a Big Integer and producing fibonacci numbers

Code: Select all

``````#define pb push_back
#define vi vector<int>

void init (vi &num, string s) {
if(s.size()%3==1)
s = "00" + s;
else if (s.size()%3 == 2)
s = "0" + s;
for(int i=0;i<s.size();i+=3) {
num.pb((s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0'));
}
reverse(num.begin(),num.end());

}

void add(vi num1,vi num2, vi &sum) {
int carry=0;
for(int i=0;i<num1.size() || i<num2.size();i++) {
if(i<num1.size()&&i<num2.size())
sum.pb(num1[i]+num2[i]+carry);
else if(i<num1.size())
sum.pb(num1[i]+carry);
else
sum.pb(num2[i]+carry);
carry=0;
if(sum.back()>=1000) {
sum.back()-=1000;
carry=1;
}
}
if(carry)
sum.pb(1);

}

void display(vi num) {
for(int i=num.size()-1;i>=0;i--)
cout<<num[i];
}

int main() {
int n;
while(scanf("%d",&n)!=EOF) {
vi f1,f2;
init(f1,"1");
init(f2,"1");
for(int i=0;i<n;i++){
vi temp;
f1=f2;
f2=temp;
}
display(f2);
cout<<"\n";
}
return 0;
}
``````

ExUCI
New poster
Posts: 14
Joined: Sat Aug 12, 2006 3:31 am
Location: USA

### Re: 10334 - Ray Through Glasses

The output for the input 1000 has 210 digits and yours only has 199, it's just missing some zeroes Remove your code after AC xrenon
New poster
Posts: 10
Joined: Tue Sep 23, 2014 4:11 am

### Re: 10334 - Ray Through Glasses

Thank You
Deleted
Last edited by xrenon on Fri Nov 07, 2014 2:01 pm, edited 1 time in total.

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10334 - Ray Through Glasses

Why runtime error ???
Why don't you put your code into code blocks?

``````StringBuilder sb = new StringBuilder();