#include <iostream>#include <stdlib.h>using namespace std;#define FIGURE_OK 1#define FIGURE_ERROR 0#define RUN_TIM 9void InputNumber();void FigureNumber();void OutputResult();int nRet = 0;int i = 0;int j = 0;int m = 0;int n = 0;int main()...{ InputNumber(); FigureNumber(); OutputResult(); return 0;}//get a 4 bit number //ijmnvoid InputNumber()...{ int nRand = rand(); n = nRand % 10; nRand = nRand / 10; m = nRand % 10; nRand = nRand / 10; while (m == n) ...{ m = rand() % 10; } while ( (j == n) || (j == m) ) ...{ j = rand() % 10; } while ( (i == j) || (i == m) || (i == n)) ...{ i = rand() % 10; } cout << "guest number: " << i << j << m << n << endl;}//for user figure numbervoid FigureNumber()...{ int nTime = 0; int nNum = 0; int ii = 0; int jj = 0; int mm = 0; int nn = 0; int nA = 0; int nB = 0; for (nTime = 0; nTime < RUN_TIM; nTime++) ...{ nA = 0; nB = 0; cout << "you still have " << RUN_TIM - nTime << " chances!" << endl; cout << "please input a 4 bit number:" << endl; cin >> nNum; if ( (nNum >= 10000) || (nNum <= 100) ) ...{ continue; } nn = nNum % 10; nNum = nNum / 10; mm = nNum % 10; nNum = nNum / 10; jj = nNum % 10; jj = nNum / 10; ii = nNum % 10; //can't be equal if ( (ii == jj) || (ii == mm) || (ii == nn) || (jj == mm) || (jj == nn) || (mm == nn)) ...{ cout << "the 4 bit number can't be equal to each other!" << endl; continue; } if (nn == n) ...{ nA++; } if (mm == m) ...{ nA++; } if (jj == j) ...{ nA++; } if (ii == i) ...{ nA++; } if ( (nn == m) || (nn == j) || (nn == i) ) ...{ nB++; } if ( (mm == n) || (mm == j) || (mm == i) ) ...{ nB++; } if ( (jj == m) || (jj == n) || (jj == i) ) ...{ nB++; } if ( (ii == m) || (ii == n) || (ii == j) ) ...{ nB++; } if (nA == 4) ...{ cout << "you are so smart!" << endl; break; } else ...{ cout << "figure result: " << nA << "A" << nB << "B" << endl; } } if (nTime < RUN_TIM) ...{ nRet = FIGURE_OK; } else ...{ nRet = FIGURE_ERROR; }}//out the figure resultvoid OutputResult()...{ if (FIGURE_OK == nRet) ...{ cout << "figure number successfully!" << endl; } else if (FIGURE_ERROR == nRet) ...{ cout << "figure number failed!" << endl; } else ...{ cout << "programe run error!" << endl; }}