TOPIC

100% Wrong(C++)

Md. Ron asked 2 months ago

*** I am unable to find the mistakes. Any suggestions from experts will be a great help.

include <bits/stdc++.h>

using namespace std;

int main() { int T; int count=0; vector V; while(cin >> T){ int X[T], Y[T], Z[T], check[T]; string N[T]; int E[T]; char S[T];

    //-----------------------
    for (int i = 0; i < T; i++){
        cin >> X[i] >> Y[i] >> Z[i];
    }

    for (int i = 0; i < T; i++){
        cout << X[i] << " " << Y[i] << "=" << Z[i] << "\n";
    }

    //-----------------------
    for (int i = 0; i < T; i++){
         cin >> N[i];
         cin.ignore();
         cin >> E[i];
         cin.ignore();
         cin >> S[i];
    }

    //-----------------------
    for(int i = 0; i < T; i++){
         if (S[i] == '+') {
            if ((X[E[i]-1]+Y[E[i]-1]) == Z[E[i]-1]) check[i] = 1;
            else check[i] = 0;
         }
         else if (S[i] == '-'){
            if ((X[E[i]-1]-Y[E[i]-1]) == Z[E[i]-1]) check[i] = 1;
            else check[i] = 0;
         }
         else if (S[i] == '*'){
            if ((X[E[i]-1]*Y[E[i]-1]) == Z[E[i]-1]) check[i] = 1;
            else check[i] = 0;
         }
         else if (S[i] == 'I'){
            if ((X[E[i]-1]+Y[E[i]-1] != Z[E[i]-1]) || (X[E[i]-1]-Y[E[i]-1] != Z[E[i]-1]) || (X[E[i]-1]*Y[E[i]-1] != Z[E[i]-1])) check[i] = 1;
            else check[i] = 0;
         }
    }

    //------------------------------
    for(int i = 0; i < T; i++){
        //cout << check[i];
        if(check[i] == 1) count++;
    }

    //------------------------------
    if (count == T) cout << "You Shall All Pass!";
    else if (count == 0) cout << "None Shall Pass!";
    else{
    for(int i = 0; i < T; i++){
        if(check[i] == 0){
            V.push_back(N[i]);
        }
    }
    string temp;
    for(int i = 0; i < V.size()-1; i++){
        if(V[i] > V[i+1]){
            temp = V[i+1];
            V[i+1] = V[i];
            V[i] = temp;
        }
    }
    for(int i = 0; i < V.size(); i++){
        cout << V[i] << " ";
    }
    cout << "\n";
    }

    count = 0;
}
return 0;

}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 2 months ago

    Lines #6-8:

        for (int i = 0; i < T; i++){
            cout << X[i] << " " << Y[i] << "=" << Z[i] << "\n";
        }

    Why? Is it debug info or what?