fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int magic(map<char, int> &v, const string str) // arvutab s6na arvulise v22rtuse
  9. {
  10. int sum = 0, i = 0;
  11. for (auto it = str.rbegin(); it != str.rend(); ++it, ++i)
  12. {
  13. sum += pow(10, i) * v[*it];
  14. }
  15. return sum;
  16. }
  17.  
  18. bool unique(map<char, int> &v) // kontrollib kas k6ik numbrid on unikaalsed
  19. {
  20. for (auto it1 = v.begin(); it1 != v.end(); ++it1)
  21. {
  22. auto it2 = it1;
  23. ++it2;
  24. for (;it2 != v.end(); ++it2)
  25. {
  26. if (it1->second == it2->second)
  27. {
  28. return false;
  29. }
  30. }
  31. }
  32. return true;
  33. }
  34.  
  35. int main()
  36. {
  37. map<char, int> v;
  38. for (char c : string("KRONAFRANK")) // lisab kasutatavad t2hed
  39. {
  40. v[c] = 0;
  41. }
  42.  
  43. bool end = false;
  44. while (!end)
  45. {
  46. if ((3 * magic(v, "KRONA") == magic(v, "FRANK")) && unique(v)) // kontrollib lahendust
  47. {
  48. for (auto p : v)
  49. {
  50. cout << p.first << ":" << p.second << "; ";
  51. }
  52. cout << endl;
  53. }
  54.  
  55. v.begin()->second++; // suurendab esimest numbrit
  56. for (auto it = v.begin(); it != v.end(); ++it)
  57. {
  58. if (it->second > 9) // carry
  59. {
  60. auto it2 = it;
  61. it2++;
  62. if (it2 != v.end())
  63. {
  64. it->second = 0;
  65. it2->second++;
  66. }
  67. else // l6petamine
  68. {
  69. end = true;
  70. }
  71. }
  72. else
  73. {
  74. break;
  75. }
  76. }
  77. }
  78. return 0;
  79. }
  80.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:38:17: error: expected initializer before ':' token
prog.cpp:44:5: error: expected primary-expression before 'while'
prog.cpp:44:5: error: expected ')' before 'while'
prog.cpp:48:25: error: expected initializer before ':' token
prog.cpp:53:9: error: expected primary-expression before '}' token
prog.cpp:53:9: error: expected ')' before '}' token
prog.cpp:53:9: error: expected primary-expression before '}' token
prog.cpp:53:9: error: expected ';' before '}' token
stdout
Standard output is empty