1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
#include <iostream> #include <string> #include <stdio.h> #include <string.h> #define max(a,b) (a)>(b)?(a):(b) #define size 350 using namespace std; struct bignum{ int s[size]; int len; bignum() { len = 1; memset(s,0,sizeof(s)); } bignum operator = (const char *str) { len = strlen(str); for(int i= 0;i<len;i++) { s[len-1-i] = str[i]-'0'; } return *this; } bignum operator = (const int num) { char ch[300]; sprintf(ch,"%d",num); *this = ch; return *this; } bignum(const char *str) { *this = str; } bignum(const int num) { *this = num; } bignum operator +(const bignum &big) { bignum sum; sum.len = max(this->len,big.len);//((this->len) >= (big.len) ? (this->len) : (big.len) ); int tmp=0; for(int i=0;i<sum.len;i++) { if(i<this->len) tmp+=this->s[i]; if(i<(big.len)) tmp+=(big.s[i]); sum.s[i] = tmp%10; tmp/=10; } while(tmp) { sum.s[sum.len++] = tmp%10; tmp/=10; } return sum; } bignum operator -(const bignum &big) { bignum sub; sub.len = ((this->len) >= (big.len) ? (this->len) : (big.len) ); int i=0; for(i=0;i<big.len;i++) { if((this->s[i])<big.s[i]) { this->s[i]+=10; this->s[i+1]--; } sub.s[i] = (this->s[i])-big.s[i]; } for(;i<(this->len);i++) { if(this->s[i]<0) { this->s[i]+=10; this->s[i+1]--; } sub.s[i]=this->s[i]; } while(sub.s[sub.len-1]==0) { sub.len--; } if(sub.len==0) sub.len=1; return sub; } bool operator <(const bignum &b)const { if((this->len)!=b.len) return (this->len) < b.len; for(int i=len-1;i>=0;i--) { if(this->s[i]!=b.s[i]) return this->s[i] < b.s[i]; } return false; } bool operator >(const bignum &b)const{ return b < *this;} bool operator <=(const bignum &b)const{return !(b<(*this));} bool operator >=(const bignum &b)const{return !((*this)<b);} bool operator !=(const bignum &b)const{return (b<(*this)) || (((*this)<b));} bool operator ==(const bignum &b)const{return !(b!=*this);} void prnt() { if(len==1 && s[0]==0) printf("0"); else { for(int i=len-1;i>=0;i--) printf("%d",s[i]); } cout<<"\n"; } }; bignum fib[120]; bignum res,zero; void solve(int index) { int flag=1; for(int i=index;i>=1;i--) { if(res>=fib[i] && flag) { printf("1"); res = res - fib[i]; flag=0; } else { printf("0"); flag = 1; } } } int main() { /*string number; int num=40; sprintf(number, "%d", num); printf("%s\n",number); */ int kase=0; fib[1]="1"; fib[2]="2"; for(int i=3;i<120;i++) fib[i]= fib[i-1]+fib[i-2]; char s1[300],s2[300]; bignum sum,sum1; while(~scanf("%s%s",s1,s2)) { sum ="0"; sum1 ="0"; res="0"; if (kase ++) { printf("\n"); } for(int i=strlen(s1)-1;i>=0;i--) { if(s1[i]=='1') { sum= sum +fib[strlen(s1)-i]; } } for(int i=strlen(s2)-1;i>=0;i--) { if(s2[i]=='1') sum1=sum1 + fib[strlen(s2)-i]; } res =sum+sum1; if(res==zero) { cout<<"0\n"; continue; } else { int ind,pos; for(ind=120-1;ind>=1;ind--) { if(res>=fib[ind]) { break; } } solve(ind); printf("\n"); } } return 0; } |