Tarango

Alphabet

Jul 15th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define Mod 1000000007
  5. string s;
  6.  
  7. string char2str(char a) {
  8.     stringstream ss;
  9.     ss << a;
  10.     string str = ss.str();
  11.     return str;
  12. }
  13. map<int,int> Map;
  14.  
  15. string merge(string s){
  16.     int Len = s.length();
  17.     string t = "";
  18.     int i = 0;
  19.     while(i<Len){
  20.         t = t.append(char2str(s[i]));
  21.         int j = i+1;
  22.         while(j<Len){
  23.             if(s[j] == s[j-1]){
  24.                 j++;
  25.             }else{
  26.                 break;
  27.             }
  28.         }
  29.         if(s[i] == '?'){
  30.             Map[t.length()-1] = (j-i);
  31.         }
  32.         i = j;
  33.     }
  34.     return t;
  35. }
  36.  
  37. string build(){
  38.     string t = merge(s);
  39.     cout << t << endl;
  40.     int Len = t.length();
  41.     if(Len > 1){
  42.         if(t[0] == '?') t[0] = t[1];
  43.         if(t[Len-1] == '?') t[Len-1] = t[Len-2];
  44.     }
  45.     int i = 1;
  46.     while(i<Len-1){
  47.         if(t[i] == '?'){
  48.             if(t[i-1] == t[i+1]){
  49.                 t[i] = t[i-1];
  50.             }
  51.         }
  52.         i++;
  53.     }
  54.     //t = merge(t);
  55.     cout << t << endl;
  56.     return t;
  57. }
  58.  
  59. long long calc(){
  60.     Map.clear();
  61.     string t = build();
  62.     int Len = t.length();
  63.     long long res = 0;
  64.     for(int i = 0;i<Len;i++){
  65.         if(t[i] == '?'){
  66.             res = (res + Map[i] + 1)%Mod;
  67.         }
  68.     }
  69.     if(res == 0) res = 1;
  70.     return res;
  71. }
  72.  
  73. int main(){
  74.     int nCase;
  75.     cin >> nCase;
  76.     for(int cs = 1;cs<=nCase;cs++){
  77.         cin >> s;
  78.         long long res = calc();
  79.         cout << res << endl;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment