Advertisement
TLE

10098

TLE
Apr 20th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include<cstdio>
  2. #include<sstream>
  3. #include<cstdlib>
  4. #include<cctype>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<set>
  8. #include<queue>
  9. #include<stack>
  10. #include<list>
  11. #include<iostream>
  12. #include<fstream>
  13. #include<numeric>
  14. #include<string>
  15. #include<vector>
  16. #include<cstring>
  17. #include<map>
  18. #include<iterator>
  19.  
  20. using namespace std;
  21.  
  22. char permutation[12];
  23.  
  24. void acseding(char N[])
  25. {
  26. char temp;
  27. for(int I=0; I<strlen(N); I++)
  28. {
  29. for(int J=I+1; J<strlen(N); J++)
  30. {
  31. if(N[I] > N[J])
  32. {
  33. temp = N[I];
  34. N[I] = N[J];
  35. N[J] = temp;
  36. }
  37. }
  38. }
  39. }
  40.  
  41. void P(int k,char w[],int ln,int check[])
  42. {
  43. if(k == ln)
  44. {
  45. permutation[k] = '\0';
  46. printf("%s\n",permutation);
  47. return;
  48. }
  49. else
  50. {
  51. for(int x=0; x<strlen(w); x++)
  52. {
  53. if(check[x] == 0)
  54. {
  55. check[x] = 1;
  56. permutation[k] = w[x];
  57. k++;
  58. P(k,w,ln,check);
  59. check[x] = 0;
  60. k--;
  61. }
  62. }
  63. }
  64. }
  65.  
  66. int main()
  67. {
  68. char test[10];
  69. gets(test);
  70. int t = atoi(test);
  71. while(t--)
  72. {
  73. char word[12];
  74. int che[12]={0};
  75. permutation[0] = '\0';
  76. gets(word);
  77. acseding(word);
  78. int lnth = strlen(word);
  79. P(0,word,lnth,che);
  80. cout << "\n";
  81. }
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement