Digital problems (c ++ implementation), digital

Source: Internet
Author: User

Digital problems (c ++ implementation), digital

Description: The LCD digital tube uses ten numbers represented by seven numbers. The horizontal and vertical short strokes are called one stroke, that is, there are three strokes in 7 and seven strokes in 8. 10 digits must be arranged.
Two Adjacent numbers can both be composed of another number plus or minus a few, but cannot be added or subtracted. For example, 7 → 3 is allowed, and 7 → 2 is not allowed. Enter a group of numbers to determine whether the group meets the preceding rules.

Input: enter a value ranging from 0 ~ 9. Separate numbers with spaces and end with-1 as the input.

Output: Enter YES or NO.

Input:

4107395682 3  5 1 6  2  7 9  0  4  80
output:
YESNO

Analysis: there is a way to order each table so that each number can be expressed as a string, for example, 1 is "35 ", then, determine whether the adjacent two match the rule. You can use a character string with a larger number segment to determine whether it is a subset of a larger string.

1 # include <iostream> 2 # include <string> 3 using namespace std; 4 5 // determine whether the adjacent two can convert each other to 6 int s (string max, string min) 7 {8 int n = 0; 9 for (int I = 0; I <min. size (); I ++) 10 {11 for (int j = 0; j <max. size (); j ++) 12 {13 if (min [I] = max [j]) 14 n ++; 15} 16} 17 if (n = min. size () 18 return 1; 19 else20 return 0; 21} 22 23 // judgment function 24 int cal (int a []) 25 {26 int k; 27 string B [10] = {"123567", "35", "23467 ", "23456", "1345", "12456", "124567", "235", "1234567", "123456 "}; // mark the 7-digit number in the digital tube with numbers 1-7 and store each number with strings 28 // compare the adjacent two 29 for (int I = 0; I <9; I ++) 30 {31 32 if (B [a [I]. size ()> B [a [I + 1]. size () 33 k = s (B [a [I], B [a [I + 1]); 34 else35 k = s (B [a [I + 1], B [a [I]); 36 if (! K) 37 return 0; 38} 39 return 1; 40} 41 42 int main () 43 {44 int a [10]; 45 while (cin> a [0]) & (a [0]! =-1) 46 {47 for (int I = 1; I <10; I ++) 48 cin> a [I]; 49 if (cal ()) 50 cout <"Yes" <endl; 51 else52 cout <"No" <endl; 53} 54 system ("pause"); 55 return 0; 56}

 

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.