Advertisement
cowalters16

Untitled

Aug 22nd, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20.  
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25. string A,W,S,Smod;
  26. int T;
  27.  
  28. cin >> T;
  29.  
  30. for(int i=0;i<T;i++)
  31. {
  32. cin >> A;
  33. cin >> W;
  34. cin >> S;
  35.  
  36. //cout<<W<<endl;
  37.  
  38. map<char,int> alpha;
  39. map<int,char> alphainverse;
  40. Smod.assign(S.size(),'0');
  41.  
  42. for(unsigned int j=0;j<A.size();j++)
  43. {
  44. alpha.insert(pair<char,int>(A[j],j));
  45. alphainverse.insert(pair<int,char>(j,A[j]));
  46. //cout<<alpha[A[j]]<<" "<<A[j]<<endl;
  47. }
  48.  
  49. vector<int> shifts;
  50.  
  51. for(unsigned int j=0;j<A.size();j++)
  52. {
  53. for(unsigned int k=0;k<S.size();k++)
  54. {
  55. Smod[k] = alphainverse[(alpha[S[k]]+j)%(A.size())];
  56. }
  57.  
  58. //cout<<Smod<<endl;
  59.  
  60. int cont=0;
  61. int occur=0;
  62.  
  63. for(unsigned int k=0;k<Smod.size();k++)
  64. {
  65. //cout<<Smod[k]<<" "<<W[cont]<<endl;
  66.  
  67. if(Smod[k]==W[cont])
  68. cont++;
  69. else if(Smod[k]==W[0])
  70. cont=1;
  71. else cont=0;
  72.  
  73. if(cont==W.size())
  74. {
  75. //cout<<"Achou";
  76. occur++;
  77. cont=0;
  78. }
  79. }
  80.  
  81. if(occur==1)
  82. {
  83. //cout<<"bizu";
  84. shifts.push_back(j);
  85. }
  86. }
  87.  
  88. for(unsigned int k=0;k<shifts.size();k++)
  89. {
  90. shifts[k] = (A.size()-shifts[k])%(A.size());
  91. }
  92.  
  93. if(shifts.size()==0)
  94. cout<<"sem solucao"<<endl;
  95.  
  96. else if(shifts.size()==1)
  97. cout<<"unica: "<<shifts[0]<<endl;
  98. else
  99. {
  100. cout<<"ambiguo:";
  101. sort(shifts.begin(),shifts.end());
  102. for(unsigned int j=0;j<shifts.size();j++)
  103. cout<<" "<<shifts[j];
  104. cout<<endl;
  105. }
  106.  
  107. shifts.clear();
  108. alpha.clear();
  109. alphainverse.clear();
  110. }
  111.  
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement