Laddu DSA Learning Series

here is the link. And here is the code I’ve written:

#include
#define ll long long
using namespace std;
int main() {
ll t;
cin>>t;
while(t–)
{
ll n;
cin>>n;
ll sum=0;
string origin;
cin>>origin;
while(n–)
{
string s;
cin>>s;
if(s==“CONTEST_WON”)
{
int rank;
cin>>rank;
if(rank<=20)
sum+=320-x;
}
else if(s==“TOP_CONTRIBUTOR”)
{
sum+=300;
}
else if(s==“BUG_FOUND”)
{
int severity;
cin>>severity;
sum+=severity;
}
else if(s==“CONTEST_HOSTED”)
{
sum+=50;
}
}
if(origin==“INDIAN”)
cout<<sum/200<<endl;
else
cout<<sum/400<<endl;
}

}

What is wrong with this?

Only one Test case is passing after submission

I cleaned up the code a little for readability

    if(s == "CONTEST_WON")
    {
        int rank; cin >> rank;
        if(rank <= 20)
        sum += 320 - x;
    }
  1. What is x? (I know x is rank, but the virtual judge doesn’t)

  2. Incase rank > 20, your code adds nothing to the sum, when it should add 300.
    Fixed:

             if(s == "CONTEST_WON")
         {
             int rank; cin >> rank;
             sum += 300;
             if(rank <= 20) sum += 20 - rank;
         }
    

Rest of the code is correct!

2 Likes