Advertisement
Spark_code

Untitled

Jun 2nd, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <algorithm>
  9. #include <cmath>
  10. #include <sstream>
  11. #include <string>
  12. #include <memory.h>
  13.  
  14. using namespace std;
  15.  
  16. void prepare()
  17. {
  18. #ifdef _DEBUG
  19.     freopen("input.txt","r",stdin);
  20.     freopen("output.txt","w",stdout);
  21. #endif
  22. cin.sync_with_stdio(false);
  23. cout.sync_with_stdio(false);
  24. }
  25.  
  26. int main()
  27. {
  28.     prepare();
  29.     int n;
  30.  
  31.     cin >> n;
  32.  
  33.     for (int j = 0; j < n; j++)
  34.     {
  35.         string s;
  36.         long long res = 1;
  37.         int k = 0, q = 0;
  38.  
  39.         cin >> s;
  40.  
  41.         for (int i = 0; i < s.length(); i++)
  42.             if (s[i] == '?')
  43.                 k++;
  44.  
  45.         for (int i = 0; i < k; i++)
  46.             res = (res * 2) % (1000 * 1000 * 1000 + 7);
  47.  
  48.         if (s.length() % 2)
  49.             cout << res;
  50.         else
  51.         {
  52.             bool flag = 0;
  53.             int q = s.length()/2;
  54.             int t = 0;
  55.  
  56.             for (int i = 0; i < q; i++)
  57.             {
  58.                 if (!(s[i] == s[i + q] || s[i] == '?' || s[i + q] == '?'))
  59.                     flag = 1;
  60.                 if (s[i] == '?' && s[i + q] == '?')
  61.                     t++;
  62.             }
  63.             if (flag)
  64.                 cout << res;
  65.             else
  66.                 cout << res - 1 - t;
  67.         }
  68.  
  69.         cout << endl;
  70.            
  71.     }
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement