fork(1) download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. class Variable
  5. {
  6. private:
  7. std::vector<char> mValue; // 紀錄,例如 mValue = 1?2??
  8. int mMaxN; // 有多少種變化型
  9. public:
  10. void Set(std::string v)
  11. {
  12. mMaxN = 1;
  13. for (unsigned i = 0; i < v.size() ; ++i)
  14. {
  15. if (v[i] >= '0' && v[i] <= '9')
  16. {
  17. mValue.push_back(v[i]);
  18. }
  19. else
  20. {
  21. mValue.push_back('?');
  22. mMaxN *= 10;
  23. }
  24. }
  25. }
  26. unsigned GetMaxN()const // 有多少種變化型[0 ~ N-1]
  27. {
  28. return mMaxN;
  29. }
  30. unsigned GetValue(unsigned Nth)const //獲得第 N 大的資料
  31. {
  32. unsigned res = 0;
  33. unsigned pow = 1;
  34. for (int i = mValue.size() - 1; i >= 0; --i)
  35. {
  36. if (mValue[i] == '?')
  37. {
  38. res += (Nth % 10) * pow;
  39. Nth /= 10;
  40. }
  41. else
  42. {
  43. res += (mValue[i] - '0') * pow;
  44. }
  45. pow *= 10;
  46. }
  47. return res;
  48. }
  49. };
  50.  
  51. int main()
  52. {
  53. Variable vX, vY, vZ;
  54. std::string strX, strY, strZ;
  55. std::cin >> strX >> strY >> strZ;
  56. vX.Set(strX);
  57. vY.Set(strY);
  58. vZ.Set(strZ);
  59. for (unsigned xx = 0; xx < vX.GetMaxN(); ++xx)
  60. {
  61. for (unsigned yy = 0; yy < vY.GetMaxN(); ++yy)
  62. {
  63. for (unsigned zz = 0; zz < vZ.GetMaxN(); ++zz)
  64. {
  65. if (vX.GetValue(xx)*vY.GetValue(yy) == vZ.GetValue(zz))
  66. {
  67. std::cout << vX.GetValue(xx) << "x" << vY.GetValue(yy) << "=" << vZ.GetValue(zz) << std::endl;
  68. }
  69. }
  70. }
  71. }
  72. system("Pause");
  73. return 0;
  74. }
Success #stdin #stdout #stderr 0.02s 15240KB
stdin
a1b2
3c
4d5ef
stdout
1122x37=41514
1142x39=44538
1172x38=44536
1182x36=42552
1192x34=40528
stderr
sh: 1: Pause: not found