11.17 Job Problem c:sequence Problem (II): practice__ Mt., Hkust OJ

Source: Internet
Author: User
Description

An integer sequence is a sequence of integers in a particular order in which the length of an integer sequence is the number of integers in the sequence, and an integer series with a negative length is not defined.

The sum of two integer sequences A and B is defined as a new integer sequence C, the length of sequence C is the longer one in both A and B, and the integer at each position of sequence C is the sum of A and b corresponding position. If the sequence A and B are unequal, it may be assumed that a is more than B, then the part of the sequence C which is more than B is considered to be the integer on the corresponding position of a and the sum of 0.

Your task is to compute the same number of integer sequences that match certain requirements, and the integers in these sequences are nonnegative integers less than 1000. Input

The first behavior of the input is an integer m (m>0), followed by an M line input. Each row is entered as an integer sequence of no more than 1000 integers, and the input of each integer sequence ends with 0. Output

Add the integer sequence 22 of the input: line 1th and line 2nd Add, line 3rd and 4th ... Output sequentially: One integer sequence per row, separated by a single space for each two integer. If the number of sequences is not even, it is added as an integer sequence with a length of 0.

It is worth noting that an integer sequence of length 0 should also have output, even if there is no integer output, should also occupy a row, because "output one integer sequence per line." Sample Input 3 1 2 3 0 0 0 # Output 11 17 23 30 50 100 200 300 400 C5>hint

There is at least one array to use to save the number of integers or integer sequences. An easy way to do this is to define the array a little bit larger, because sometimes your program might not be able to handle the boundary too well.

Ideas:

Similar to B, the difference is the way of input.

A two-dimensional array should be simpler.



Code:

#include <stdio.h> #include <string.h>//c int main () {int a[1002]={0};
    int b[1002]={0};
    int c[1002]={0};
    int i,j,k=0;
    int D;
    int z;
    int s;
    scanf ("%d", &d);
        for (z=1;z<=d;z++) {k++; if (k%2!=0) {for (i=0;;;
                i++)//assignment array until 0 o'clock break {scanf ("%d", &a[i]);
                if (a[i]==0) {a[i]= ' ";
                Break }} else {for (j=0; j + +)/ditto {scanf ("%d", &b[
                J]);
                if (b[j]==0) {b[j]= ' ";
                Break {if (i>j) {f}}} if (k%2==0)//Two output time
                or (s=0; s<i; s++) {c[s]=a[s]+b[s];
                    For (s=0 s<i; s++) {if (s==0) printf ("%d", c[0]);
                else printf ("%d", c[s]);
                printf ("\ n");
                memset (A,0,sizeof (a));
                Memset (b,0,sizeof (b));
            Memset (C,0,sizeof (c)); else {for (s=0; s<j; s++) {C[s]=a[s]+b[s
                ]; For (s=0 s<j; s++) {if (s==0) printf ("%d", c[0
                    ]);
                else printf ("%d", c[s]);
                printf ("\ n");
                memset (A,0,sizeof (a));
                Memset (b,0,sizeof (b));
            Memset (C,0,sizeof (c));
                } if (K==d&&d%2==1) {for (s=0 s<i; s++) {if (s==0)
            printf ("%d", a[s]);
else printf ("%d", a[s]);        printf ("\ n");
    } if (K==d&&d%2==1&&strlen (a) ==0)//The use of this strlen should be incorrect, but somehow it's over. {printf ("\ n");}
 }
}


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.