fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool contains123(int num) {
  5. bool has1 = false, has2 = false, has3 = false;
  6.  
  7. while (num > 0) {
  8. int digit = num % 10;
  9.  
  10. if (digit == 1) has1 = true;
  11. else if (digit == 2) has2 = true;
  12. else if (digit == 3) has3 = true;
  13.  
  14. num /= 10;
  15. }
  16.  
  17. return has1 && has2 && has3;
  18. }
  19.  
  20. int main() {
  21. vector<int> arr;
  22. int x;
  23.  
  24. // Read input numbers until EOF
  25. while (cin >> x) {
  26. arr.push_back(x);
  27. }
  28.  
  29. vector<int> ans;
  30.  
  31. for (int num : arr) {
  32. if (contains123(num)) {
  33. ans.push_back(num);
  34. }
  35. }
  36.  
  37. if (ans.empty()) {
  38. cout << -1;
  39. } else {
  40. sort(ans.begin(), ans.end());
  41.  
  42. for (int i = 0; i < ans.size(); i++) {
  43. if (i > 0) cout << ",";
  44. cout << ans[i];
  45. }
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 5320KB
stdin
1456
345671
4328
12
stdout
-1