fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <functional>
  6. #include <time.h>
  7. bool check(std::string& t);
  8.  
  9. int main() {
  10. clock_t begin=clock();
  11. std::map<char,int> g;
  12. std::string d("sendmory");
  13. for(auto c: d)
  14. g[c] = 0;
  15. for(int i = 10000000; i <= 99999999; i++){
  16. std::string temp = std::to_string(i);
  17. if(check(temp)){
  18. int j=0;
  19. for(auto a: d){
  20. g[a] = temp[j] -'0';
  21. j++;
  22. }
  23. if(g[d[4]] && g[d[0]]){
  24. int sl1,sl2,sl3;
  25. sl1 = g[d[0]]*1000 + g[d[1]]*100 + g[d[2]]*10 + g[d[3]];
  26. sl2 = g[d[4]]*1000 + g[d[5]]*100 + g[d[6]]*10 + g[d[1]];
  27. sl3 = g[d[4]]*10000 + g[d[5]]*1000 + g[d[2]]*100 + g[d[1]]*10 + g[d[7]];
  28. if(sl1+sl2 == sl3) {
  29. for (auto c:g)
  30. std::cout << c.first << " = " << c.second << "\n";
  31. std::cout << sl3 <<"\n";
  32. break;
  33. }
  34.  
  35. }
  36.  
  37. }
  38.  
  39. }
  40. clock_t end=clock();
  41. std::cout << end - begin;
  42. return 0;
  43. }
  44.  
  45. bool check(std::string& t){
  46. for(int i=0; i < t.size();i++){
  47. for(int j = i+1; j <t.size();j++)
  48. if(t[i]==t[j])
  49. return false;
  50. }
  51. return true;
  52. }
Time limit exceeded #stdin #stdout 5s 4412KB
stdin
Standard input is empty
stdout
Standard output is empty