P1008.cpp 788 B

1234567891011121314151617181920212223242526272829303132
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. using namespace std;
  6. int main() {
  7. vector<string> solutions;
  8. for (int i = 1; i <= 3; ++i) {
  9. for (int j = 1; j <= 9; ++j) {
  10. for (int k = 1; k <= 9; ++k) {
  11. int num = 100*i+10*j+k;
  12. int two_times = 2 * num;
  13. int three_times = 3 * num;
  14. string arr = to_string(num).append(to_string(two_times).append(to_string(three_times)));
  15. sort(arr.begin(), arr.end());
  16. if (arr.size() != 9) goto END;
  17. for (int a = 1; a < arr.size(); ++a) {
  18. if (arr[a-1] != a+48)
  19. goto END;
  20. }
  21. solutions.push_back(to_string(num) + " " + to_string(two_times) + " " + to_string(three_times));
  22. END:
  23. ;
  24. }
  25. }
  26. }
  27. for (auto solution : solutions) {
  28. cout << solution << endl;
  29. }
  30. return 0;
  31. }