Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define Mod 1000000007
- string s;
- string char2str(char a) {
- stringstream ss;
- ss << a;
- string str = ss.str();
- return str;
- }
- map<int,int> Map;
- string merge(string s){
- int Len = s.length();
- string t = "";
- int i = 0;
- while(i<Len){
- t = t.append(char2str(s[i]));
- int j = i+1;
- while(j<Len){
- if(s[j] == s[j-1]){
- j++;
- }else{
- break;
- }
- }
- if(s[i] == '?'){
- Map[t.length()-1] = (j-i);
- }
- i = j;
- }
- return t;
- }
- string build(){
- string t = merge(s);
- cout << t << endl;
- int Len = t.length();
- if(Len > 1){
- if(t[0] == '?') t[0] = t[1];
- if(t[Len-1] == '?') t[Len-1] = t[Len-2];
- }
- int i = 1;
- while(i<Len-1){
- if(t[i] == '?'){
- if(t[i-1] == t[i+1]){
- t[i] = t[i-1];
- }
- }
- i++;
- }
- //t = merge(t);
- cout << t << endl;
- return t;
- }
- long long calc(){
- Map.clear();
- string t = build();
- int Len = t.length();
- long long res = 0;
- for(int i = 0;i<Len;i++){
- if(t[i] == '?'){
- res = (res + Map[i] + 1)%Mod;
- }
- }
- if(res == 0) res = 1;
- return res;
- }
- int main(){
- int nCase;
- cin >> nCase;
- for(int cs = 1;cs<=nCase;cs++){
- cin >> s;
- long long res = calc();
- cout << res << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment