Ankit_132

D

Nov 15th, 2023
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8. int main()
  9. {
  10.     int t;
  11.     cin>>t;
  12.  
  13.     while(t--)
  14.     {
  15.         int n;
  16.         string s;
  17.         cin>>n>>s;
  18.  
  19.         int tot = 0;
  20.         int rem = 0;
  21.         for(auto e: s)
  22.         {
  23.             if(e != '?')
  24.                 tot += (e - '0');
  25.             else
  26.                 rem++;
  27.         }
  28.  
  29.         if(rem==1 && s[0]!='?' && tot%9==0)
  30.         {
  31.             cout<<2<<"\n";
  32.             continue;
  33.         }
  34.  
  35.         cout<<1;
  36.         for(int i=1; i<rem; i++)
  37.             cout<<1 - (s[0]=='?') + (i==rem-1 && tot%9==0 && s[0]!='?');
  38.         cout<<"\n";
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment