fork(29) download
  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<cstring>
  4. #include<map>
  5. using namespace std;
  6. map<string,bool>present;
  7. int main()
  8. {
  9. string text[5001];
  10. char t[1000];
  11. int no=0;
  12. while(scanf("%s",t)==1)
  13. text[no++]=t;
  14. int alpha[no][26],num[no][10];
  15. for(int i=0;i<no;i++)
  16. {
  17. for(int j=0;j<26;j++)
  18. alpha[i][j]=0;
  19. for(int j=0;j<10;j++)
  20. num[i][j]=0;
  21. }
  22. for(int i=0;i<no;i++)
  23. {
  24. int len=text[i].length();
  25. for(int j=0;j<len;j++)
  26. if(text[i][j]>='a'&&text[i][j]<='z')
  27. alpha[i][text[i][j]-'a']++;
  28. else if(text[i][j]>='A'&&text[i][j]<='Z')
  29. alpha[i][text[i][j]-'A']++;
  30. else if(text[i][j]>='0'&&text[i][j]<='9')
  31. num[i][text[i][j]-'0']++;
  32. }
  33. bool arr[no];
  34. for(int i=0;i<no;i++)
  35. arr[i]=0;
  36. for(int i=0;i<no;i++)
  37. {
  38. string ans="";
  39. bool yes=0;
  40. if(!arr[i])
  41. {
  42. int flag=0;
  43. for(int j=i+1;j<no;j++)
  44. {
  45. if(!arr[j])
  46. {
  47. bool flag1=0;
  48. for(int z=0;z<26;z++)
  49. {
  50. if(alpha[i][z]!=alpha[j][z])
  51. {
  52. flag1=1;
  53. break;
  54. }
  55. }
  56. if(!flag1)
  57. {
  58. for(int z=0;z<10;z++)
  59. {
  60. if(num[i][z]!=num[j][z])
  61. {
  62. flag1=1;
  63. break;
  64. }
  65. }
  66. }
  67. if(!flag1&&!flag)
  68. {
  69. present[text[i]]=1;
  70. if(present[text[j]])
  71. {
  72. present[text[j]]=0;
  73. goto end;
  74. }
  75. present[text[j]]=1;
  76. flag=1;
  77. int l1=text[i].length();
  78. arr[i]=arr[j]=1;
  79. for(int q=0;q<l1;q++)
  80. {
  81. if(text[i][q]>='0'&&text[i][q]<='9')
  82. ans+=text[i][q];
  83. else if(isalnum(text[i][q]))
  84. {
  85. if(text[i][q]>='A'&&text[i][q]<'a')
  86. ans+=text[i][q]-'A'+'a';
  87. else if(text[i][q]>='a')
  88. ans+=text[i][q];
  89. }
  90. }
  91. if(ans[ans.length()-1]!=' ')
  92. ans+=' ';
  93. l1=text[j].length();
  94. for(int q=0;q<l1;q++)
  95. {
  96. if(text[j][q]>='0'&&text[j][q]<='9')
  97. ans+=text[j][q];
  98. else if(isalnum(text[j][q]))
  99. {
  100. if(text[j][q]>='A'&&text[j][q]<'a')
  101. ans+=(text[j][q]-'A'+'a');
  102. else if(text[j][q]>='a')
  103. ans+=text[j][q];
  104. }
  105. }
  106. if(ans[ans.length()-1]!=' ')
  107. ans+=' ';
  108. yes=1;
  109. }
  110. else if(!flag1&&!present[text[j]])
  111. {
  112. int l1=text[i].length();
  113. present[text[j]]=1;
  114. arr[j]=1;
  115. for(int q=0;q<l1;q++)
  116. {
  117. if(text[j][q]>='0'&&text[j][q]<='9')
  118. ans+=text[j][q];
  119. else if(isalnum(text[j][q]))
  120. {
  121. if(text[j][q]>='A'&&text[j][q]<'a')
  122. ans+=(text[j][q]-'A'+'a');
  123. else if(text[j][q]>='a')
  124. ans+=text[j][q];
  125. }
  126. }
  127. if(ans[ans.length()-1]!=' ')
  128. ans+=' ';
  129. yes=1;
  130. }
  131. end:;
  132. }
  133. }
  134. if(yes)
  135. {
  136. int l=ans.length()-1;
  137. for(int h=0;h<l;h++)
  138. putchar_unlocked(ans[h]);
  139. putchar_unlocked('\n');
  140. }
  141. }
  142. }
  143. return 0;
  144. }
Success #stdin #stdout 0s 3484KB
stdin
Parts of the world have sunlight for close to 24 hours during summer. Dan went to the north pole to lead an expedition during summer. He had a strap on his head to identify himself as the leader. Dan had to deal with the sun never going down for 42 consecutive days and his leadership strap soon became a blindfold. He wondered what kind of traps lay ahead of him.
stdout
parts strap traps
24 42
dan and
lead deal