Number a minus a number to get B, give A and B and N to ask for all possible number a

Source: Internet
Author: User

Not much nonsense. Comments in Source code

/*file:abn.cdate:2015/4/4version:1.0platform:windows 7 x86_64function:a + B = N1 <= N <= 10^9B is a minus a number to get For example A + B = 34A can be 27 or 31 special cases: one + 1  will execute two times  110 bits, minus 10 bits and digits. Therefore, you can use an array to save the final output of the result.  */#include <stdio.h>int main (int argc, char *argv[]) {int arr[10] = {0,};int nsrc, Nchg, Nres;int j;scanf ("%d", &nres), if (nres <=) {printf ("%d\n", nres); return 0;} for (nsrc = ten; nsrc <= nres; ++nsrc) {int ntmp = NSRC, nindex;/* initialize array */for (j = 9; ntmp > 0 && J >= 0;--j {Arr[j] = ntmp% 10;ntmp/= 10;} /* Save Index */nindex = j + 1;/* Each element of the array is processed  8765*/for (j = 9; J >= NIndex;--j) {nchg = 0;for (ntmp = nIndex; ntmp <= 9; + +) NTMP) {if (ntmp! = j) {Nchg = Nchg * + arr[ntmp];  }} if (nchg + nsrc = = nres) {printf ("%d +%d =%d\n", NSRC, Nchg, nres);}} /* Restore array values for the next cycle using */for (j = 0; J <; ++j) {arr[j] = 0;}} return 0;}
Run results

87654
78827 + 8827 = 87654
79677 + 7977 = 87654
79686 + 7968 = 87654
79687 + 7967 = 87654
79692 + 7962 = 87654
79727 + 7927 = 87654
79827 + 7827 = 87654
83827 + 3827 = 87654

34
27 + 7 = 34
31 + 3 = 34
32 + 2 = 34

Number a minus a number to get B, give A and B and N to ask for all possible number a

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.