Блог пользователя sjp1114

Автор sjp1114, история, 2 года назад, По-английски

Hello! I am having trouble debugging my code because I don't know why it doesn't work. The logic seems to be straightforward and I feel like I handle edge cases where 0 wraps to 9 and viceversa!

include <bits/stdc++.h>

using namespace std;

void solve() { //number of wheels for the test case we're on! int n; cin >> n; vector wheels(n); //store the initial state of the wheels in some vector! for(int i = 0; i < n; i++){ int cur; cin >> cur; wheels.push_back(cur); } //then iterate through each of n wheels the number and type of moves made! //decode each move! int num_moves; string series; //decode for every ath wheel! for(int a = 0; a<n; a++){ cin >> num_moves >> series; int index = 0; //as long as we didn't process each and every move, keep processing each move to //decypher for current ath wheel! while(num_moves--){ if(series[index] == 'U'){ if(wheels[a] == 0){ wheels[a] = 9; index++; continue; } else{ wheels[a] = wheels[a] — 1; index++; continue; } } else{ if(wheels[a] == 9){ wheels[a] = 0; index++; continue; } else{ wheels[a] = wheels[a] + 1; index++; } } } }

//once we decode for all n wheels, we need to simply print out!
for(int c = 0; c < n; c++){
    cout << wheels[c] << " ";
}
//also start a new line!
cout << endl;

}

int main(){ int t; cin >> t; while(t--){ solve(); }

}

  • Проголосовать: нравится
  • -10
  • Проголосовать: не нравится