fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int func(string a,string s)
  10. {
  11. int l=a.size(),i;
  12. vector<char>c,c2;
  13.  
  14. for(i=0; i<l; i++)
  15. {
  16. if(isalpha(a[i]))
  17. {
  18. c.push_back(a[i]);
  19. }
  20. }
  21. sort(c.begin(),c.end());
  22.  
  23. int l2=s.size();
  24.  
  25. for(i=0; i<l2; i++)
  26. {
  27. if(isalpha(s[i]))
  28. {
  29. c2.push_back(s[i]);
  30. }
  31. }
  32. sort(c2.begin(),c2.end());
  33.  
  34. if(c==c2)
  35. {
  36. return 1;
  37. }
  38.  
  39. else
  40. {
  41. return 0;
  42. }
  43. }
  44.  
  45. int main()
  46. {
  47. int t,i,j,k,g;
  48. string s;
  49.  
  50. cin>>t;
  51. getchar();
  52. cout<<endl;
  53.  
  54. for(i=1; i<=t; i++)
  55. {
  56. vector<string>a,ko;
  57. string t1,t2,t3;
  58.  
  59. while(getline(cin,s))
  60. {
  61. if(s=="")
  62. {
  63. break;
  64. }
  65. a.push_back(s);
  66. }
  67.  
  68. for(j=0; j<a.size(); j++)
  69. {
  70. for(k=j+1; k<a.size(); k++)
  71. {
  72. g=func(a[j],a[k]);
  73.  
  74. if(g==1)
  75. {
  76. t1=a[j];
  77. t2=a[k];
  78.  
  79. if(t1>t2)
  80. {
  81. t3=t1;
  82. t1=t2;
  83. t2=t3;
  84. }
  85. ko.push_back(t1 + " = "+t2);
  86. }
  87. }
  88. }
  89.  
  90. sort(ko.begin(),ko.end());
  91.  
  92. for(int b=0; b<ko.size(); b++)
  93. {
  94. cout<<ko[b]<<endl;
  95. }
  96. cout<<endl;
  97. }
  98. return 0;
  99. }
Success #stdin #stdout 0s 3312KB
stdin
1

carthorse
horse
horse cart
i do not know u
ok i now donut
orchestra
stdout