読者です 読者をやめる 読者になる 読者になる

SRM404 Div1Easy RevealTriangle

class RevealTriangle {
public:
  vector <string> calcTriangle(vector <string> Q) {
    int N = Q.size();
    int cnt;
    do {
      cnt = 0;
      for(int i=0; i<N-1; i++) {
        for(int j=0; j<N-i-1; j++) {
          if(Q[i][j] == '?' && Q[i][j+1] != '?'
             && Q[i+1][j] != '?') {
            cnt ++;
            Q[i][j] = (char)('0' + ((Q[i+1][j]-'0') - (Q[i][j+1]-'0')+20)%10);
          }
          if(Q[i][j] != '?' && Q[i][j+1] == '?'
             && Q[i+1][j] != '?') {
            cnt ++;
            Q[i][j+1] = (char)('0' + ((Q[i+1][j]-'0') - (Q[i][j]-'0')+20)%10);
          }
          if(Q[i][j] != '?' && Q[i][j+1] != '?'
             && Q[i+1][j] == '?') {
            cnt ++;
            Q[i+1][j] = (char)('0' + ((Q[i][j]-'0') + (Q[i][j+1]-'0')+20)%10);
          }
        }
      }
    } while(cnt != 0);
    
    return Q;
  }
};