fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main(int argc, char** argv) {
  6. int length;
  7. int max;
  8. int count=0;
  9.  
  10. cout<<"請輸入位數:";
  11. cin>>length;
  12. //設定最大值Max Ex:3位數 -> Max=999
  13. for(int i=0;i<length;i++)
  14. {
  15. max+=9*pow(10,i);
  16. }
  17. //從 1 開始到 Max
  18. for (int i=1;i<=max;i++)
  19. {
  20. int num[length];
  21. int temp=i;
  22. //分解各位數字丟到 array[]
  23. for (int a=0;a<length;a++)
  24. {
  25. num[a]=temp%10;
  26. temp/=10;
  27. }
  28. //檢查是否有重複的數字
  29. bool repeat=0;
  30. for(int i=0;i<length-1;i++)
  31. {
  32. for(int j=i+1;j<length;j++)
  33. {
  34. if(num[i]==num[j]) repeat=1;
  35. }
  36. }
  37. //若沒重複則輸出數字 i,若有則跳過 i
  38. if(repeat==0)
  39. {
  40. cout<<i<<"\t";
  41. count++;
  42. if(count%5==0) cout<<endl;
  43. }
  44. else continue;
  45. }
  46. system("pause");
  47. return 0;
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:46:2: error: use of undeclared identifier 'system'
        system("pause");
        ^
1 error generated.
stdout
Standard output is empty