POJ3982: Sequence

Source: Internet
Author: User

The Description Series A meets the requirements of An = An-1 + An-2 + An-3, n> = 3 programming, given A0, A1, and A2, computing A99Input input contains multiple rows of data each row contains three integers A0, A1, A2 (0 <= A0, A1, A2 <= 32767) data ends with EOF Output. For each input row, Output A99 value Sample Input1 1 1 Sample output69087442470169109923566147 [cpp] # include <stdio. h> # include <string. h> # include <stdlib. h> void add (char a [], char B [], char back []) {int I, j, k, up, x, y, z, l; char * c; if (strlen (a)> strlen (B) l = strlen (a) + 2; Else l = strlen (B) + 2; c = (char *) malloc (l * sizeof (char); I = strlen (a)-1; j = strlen (B)-1; k = 0; up = 0; while (j> = 0 | I> = 0) {if (I <0) x = '0'; else x = a [I]; if (j <0) y = '0'; else y = B [j]; z = x-'0' + y-'0'; if (up) z ++; if (z> 9) {up = 1; z % = 10 ;} else up = 0; c [k ++] = z + '0'; I --; j --;} if (up) c [k ++] = '1 '; I = 0; c [k] = '\ 0'; for (k-= 1; k> = 0; k --) back [I ++] = c [k]; back [I] = '\ 0';} int main (){ Char a [1000], B [1000], c [1000], sum [1000]; int m, I; while (~ Scanf ("% s", a, B, c) {add (a, B, sum); add (c, sum, sum ); int n = 5; for (I = 1; I <= 24; I ++) {add (B, c, a); add (sum, a, ); add (c, sum, B); add (B, a, B); add (sum, a, c); add (B, c, c); add (, b, sum); add (c, sum, sum);} printf ("% s \ n", sum);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.