WA in TIDRICE

#include
#include
#include

    using namespace std;

    class user {
    public:
    string id;
    char vote;
    };

    class test{
    public:
    int n,net;
    user u[100];


    };

    bool comp(user a, user b)
    {
    return (a.id>b.id);  // Or
    //return lexicographical_compare( a.id.begin(), a.id.end() , b.id.begin(), b.id.end());
    }


    int main(){
    int t;
    long long int c;
    cin>>t;
    test s[t];
    for(int i=0;i<t;i++)
    {
    cin>>s[i].n;
    for(int j=0;j<s[i].n;j++)
    cin>>s[i].u[j].id>>s[i].u[j].vote;

    }

    for(int i=0;i<t;i++)
    {

    sort(s[i].u , s[i].u+s[i].n , comp);


    if(s[i].u[0].vote=='+')
    c=1;
    else
    c=-1;




    for(int j=1;j<s[i].n;j++)
    {

    if(s[i].u[j-1].id == s[i].u[j].id)
    {
    if(s[i].u[j-1].vote=='-')
    c++;
    else
    c--;

    if(s[i].u[j].vote=='+')
    c++;
    else
    c--;

    }
    else
    {
    if(s[i].u[j].vote=='+')
    c++;
    else
    c--;

    }

    }

    cout<<c<<endl;

      }
    return 0;
    }

I am getting WA when i submit the code, This codes gives correct output for the provided sample test cases… Please point out some case in which i’ll get WA…

Thanks

You are not using stable_sort function which gaurantees that if two user have same name the one which occurs earlier in the list placed first.

1 Like
//