Advertisement
leanchec

C.cpp

Nov 4th, 2023
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int modulo=1e9+7;
  5.  
  6. int main(){
  7.     ios_base::sync_with_stdio(0); cin.tie(0);
  8.  
  9.     int t;
  10.     cin >> t;
  11.     while(t--){
  12.         string a;
  13.         cin >> a;
  14.  
  15.         int resp=1, aux=1, ult=-1;
  16.         if(a[0]!='?')ult=0;
  17.  
  18.         for(int i=1; i<(int)a.size(); i++){
  19.             if(a[i]=='?'){
  20.                 aux++;
  21.             }
  22.             else{
  23.                 if(ult==-1){
  24.                     aux++;
  25.                 }
  26.                 else if((i-ult)%2==0){
  27.                     if(a[i]==a[ult]){
  28.                         aux++;
  29.                     }
  30.                     else{
  31.                         aux=i-ult;
  32.                     }
  33.                 }
  34.                 else{
  35.                     if(a[i]!=a[ult]){
  36.                         aux++;
  37.                     }
  38.                     else{
  39.                         aux=i-ult;
  40.                     }
  41.                 }
  42.                 ult=i;
  43.             }
  44.             resp+=aux;
  45.             resp%=modulo;
  46.         }
  47.  
  48.         cout << resp << '\n';
  49.     }
  50.  
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement