test case is decrementing for two times???

programming

#1

this is a problem in which I have to calculate the median in a sorted array after insertion and deletion each time but the test case is decrementing for 2 times i each iteration ?? I am unable to find it :frowning:

My code is :-----
#include
#include
#include<stdio.h>
using namespace std;
multiset myset;
int main()
{

int test;
cin>>test;
int e=test;
while(test)
{
    test=test-1;
    //test++;
    char input;
    int value;
    //scanf("%c",&input);
    cin>>input;

    //scanf("%d",&value);
    cin>>value;
    if(input=='a')
    {
        //cout<<"byeeeeeeeee

“<<test<<“lsfhvfduhvl”;
myset.insert(value);
int a=myset.size();
if(a%2!=0) //odd case
{
multiset :: const_iterator it=myset.begin();
for(int i=0;i<(a/2);i++)
{
it++;
}
printf(”%d
“,*it);
//cout<<(*it)<<”
“;
}
else
{
int b,c;
multiset :: const_iterator it=myset.begin();
for(int i=0;i<(a/2);i++)
{
it++;
}
b=(*it);
it–;
c=(it);
double x= 1.0
(b+c)/2;
printf(”%.10g
“,x);
//cout<<setprecision(9)<<x<<”
";

        }
    }
    else if(input=='r')
    {
        //cout<<"hiiiiiiiiiiiii

"<<test<<“lufhvfdhsv”;

        if(myset.find(value)!=myset.end())
        {
            cout<<"hiiiiiiiiiiiii";
            myset.erase(myset.find(value));

            if(!myset.empty())
            {
                int a=myset.size();


        if(a%2!=0)  //odd case
        {
            multiset< int > :: const_iterator it=myset.begin();
            for(int i=0;i<(a/2);i++)
            {
                it++;
            }
            printf("%d

“,*it);
//cout<<(*it)<<”
“;
}
else
{
int b,c;
multiset< int > :: const_iterator it=myset.begin();
for(int i=0;i<(a/2);i++)
{
it++;
}
b=(it);
it–;
c=(it);
//cout<<1.
(b+c)/2<<"
";
double x= 1.0
(b+c)/2;
printf(”%.10g
“,x);
//cout<<setprecision(9)<<x<<”
";

        }
        }
        else
        cout<<"Wrong!

";

        }
        else
        {
            cout<<"Wrong!

";
}

    }


}
return 0;

}


#2

it is a problem of interview street


why the test case is giving me the problem ie, it is decrementing by 2 instead of 1 in each iteration ??


#3

no,its not working


if i change cin with scanf then still it is decremeting by two .
i am getting the problem in it


#4

First of all you should use scanf instead of printf… By all means avoid using cin and cout… scanf and printf are STRONGLY recommended… And can you give me the problem statement? I think that way it will be easier to help you… If I can of course.


#5


see this… its working fine here…