Guess the number of the number

xiaoxiao2021-03-06  92

/ * Author: avalon QQ: 1243128 Date: 26-10-04 14:51 Description: 0-9 This is selected from the top 4 digits, and it constitutes 4 digits, (this time only discusses the situation that they don't repeat.) Then by The program guess this value, the person guess the results, said with XAYB, a means that you guess, and this value has the correct position. B means that you guess, but the value of the position is Y. This is a program made with a filter method. . The algorithm is not very good: (* /

#include #include #include #include #include using namespace std; // global vector, used to store digital collection list number; void Init Void) {/ Initialization Vector /// for (int A = 0; a <= 9; A ) {for (INT B = 0; B <= 9; B ) {IF (a == b) Continue; for INT C = 0; c <= 9; C ) {IF (c == a || c == b) Continue; for (int D = 0; D <= 9; D ) {IF (D! = A && D! = B && D! = C) {char sa [4] = {a '0', B '0', C '0', D '0'}; String Temp (SA, SA 4); Number .push_back (temp);}}} // c end}} // a end} // Fun EndBool Comp (String SS, STRING SD, STRING INPUT) {// Compare! ! If the two numbers do not meet the requirements INPUT, return false // num_s to the number in the vector, num_d is a guess number, input is a string Int S [4], D [4]; if (ss == sd) return false; // Decompose S [0] = SS [0] - '0'; s [1] = SS [1] - '0'; S [2] = SS [2] - '0'; s [3] = SS [3] - '0'; D [0] = SD [0] - '0'; D [1] = SD [1] - '0'; d [2] = SD [2] - '0' ; D [3] = SD [3] - '0'; // xib int x = input [0] - '0'; int y = input [2] - '0'; // comp ..... ... do {INT XY = x y; // Matching number int sum = 0; for (int i = 0; i <4; i ) {for (int J = 0; j <4; j ) {IF (s [i] == d [j]) SUM ;}}}}}} (sum! = Xy) Return False;

//} while (0); do {// absolutely match X if (x) {int sum = 0; for (int i = 0; i <4; i ) {IF (s [i] == d [i ]) SUM ;} if (sum! = x) return false;}} while (0); do {// only digital match, location does not match if (y) {int sum = 0; for (int i = 0; i <4; i ) {for (int J = 0; j <4; j ) {IF (s [i] == d [j] && i! = j) SUM ;}}} (sum! = y) Return false;}} while;} void filt (string num, string infut) {// filtering! ! Num is a guess number, input is a string list :: item iput :: item {list :: item ()) {list :: item; {list :: item; // IF (Comp (* Temp, Num, INPUT == false) Number.rase (Temp);}} String Sui_ji (void) {// Random Selection in Vector Vector Temp (Number.Begin (), Number.end ()); random_shuffle (Temp.begin (), Temp.end ()); return * (Temp.begin ());} int main (void) {String Quit; do {init () DO {String Input; String Num; cout << "Enter Avalon or Avalon or 4A4B or 4A4B end!" << Endl; while (1) {Num = sui_ji (); cout << Num << '/ t' < <"Dataset also" << Number.Size () << "" "" << Endl; Cin >> Input; if (Input == "Avalon" || input == "avalon"

转载请注明原文地址:https://www.9cbs.com/read-100829.html

New Post(0)