Algorithmic competition Getting Started classic exercise 2-10 arrangement (permutation)

Source: Internet
Author: User

Exercise 2-10

The 1,2,3,....,9 consists of 3 three-digit abc,def and GHI, each using exactly once, requiring abc:def:ghi=1:2:3. Outputs all solutions.

#include <stdio.h> #include <stdlib.h> #include <string.h>int main (int argc, char *argv[]) {  int ABC, Def, Ghi;  int a[10], count = 0;    memset (A, 0, sizeof (a)); printf ("n\n");  for (ABC = 123; ABC <= 329; abc++)  {     def = 2*abc;     Ghi = 3*ABC;          A[ABC/100] = a[abc/10%10] = a[abc%10] = 1;     A[DEF/100] = a[def/10%10] = a[def%10] = 1;     A[GHI/100] = a[ghi/10%10] = a[ghi%10] = 1;     int i;     for (i = 1; I <= 9; i++)        count + = A[i];          if (count = = 9) printf ("%d%d%d\n", ABC, Def, Ghi);      Count = 0;     memset (A, 0, sizeof (a));  System ("PAUSE");  return 0;}

Summary: 1 will be all possible numbers as a one-dimensional array subscript, and finally determine whether the sum is 9, if less than 9, there will be coincident, whereas each number has only one

2 after judging, Count and array are zeroed.

Algorithmic competition Getting started classic exercise 2-10 arrangement (permutation)

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.