fork download
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. using namespace std;
  7. typedef unsigned long long llu;
  8. const int N=3005;
  9. const llu P=13;
  10. int Tc,n;
  11. int p;
  12. char s1[N],s2[N];
  13.  
  14. llu dfs(char *s){
  15. vector <int> Q;
  16. Q.clear();
  17. while (1){
  18. if (s[p]=='0'){
  19. p++;
  20. Q.push_back(dfs(s));
  21. }
  22. else if (p==n || s[p]=='1'){
  23. p++;
  24. sort(Q.begin(),Q.end());
  25. llu ret=1;
  26. for (int i=0;i<Q.size();i++)
  27. ret=(ret*P)^Q[i];
  28. return ret;
  29. }
  30. }
  31. }
  32.  
  33. int main(){
  34. scanf("%d",&Tc);
  35. while (Tc--){
  36. scanf("%s%s",s1,s2);
  37. n=strlen(s1);
  38. p=0;
  39. llu hash1=dfs(s1);
  40. p=0;
  41. llu hash2=dfs(s2);
  42. if (hash1==hash2) puts("same");
  43. else puts("different");
  44. }
  45. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty