## 11727 - Cost Cutting

Moderator: Board moderators

Zargi
New poster
Posts: 3
Joined: Tue Nov 12, 2013 6:15 pm

### 11727 - Cost Cutting

Hey guys,
I submitted this code below and the verdict was verified as wrong answer.
Actually it works, I guess.

Greetings,
Zargi

Code: Select all

``````#include <stdio.h>
#include <stdlib.h>

int main()
{
int val1,val2,val3,counter,i,result;

scanf("%d",&counter);
for(i=0;i<counter;i++){
scanf("%d %d %d",&val1,&val2,&val3);

if(val1 < val2 && val1 > val3 || val1 > val2 && val1 < val3){result=val1;}
else if(val2 < val1 && val2 > val3 || val2 > val1 && val2 < val3){result=val2;}
else if(val3 < val2 && val3 > val1 || val3 > val2 && val3 < val1){result=val3;}
printf("Case %d: %d\n",i+1,result);
}

return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11727 - Cost Cutting

Input:

Code: Select all

``````1
1000 1000 1000``````
AC output:

Code: Select all

``````Case 1: 1000
``````
Check input and AC output for thousands of problems on uDebug!

woaraka92
New poster
Posts: 9
Joined: Sun Oct 20, 2013 6:50 pm

### 11727 - Cost Cutting

whats wrong this code??

#include<stdio.h>

int main()
{
int t,a,b,c,i;
scanf("%d",&t);

for(i=1;i<=t;i++)
{
scanf("%d%d%d",&a,&b,&c);

if((a>=b && a<=c) || (a>=c && a<=b))
printf("Case %d: %d\n",i,a);
else if((b>=a && b<=c) || (b>=c && b<=a))
printf("Case %d: %d\n",i,b);
else
printf("Case %d: %d\n",i,b);
}
return 0;
}

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### Re: 11727 - Cost Cutting

What are the inputs you tried to test the code?

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11727 - Cost Cutting

Will you ever print as a result third number -> c ?
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

notfound
New poster
Posts: 1
Joined: Wed Aug 27, 2014 6:47 pm

### Re: 11727 - Cost Cutting

Code: Select all

``````#include <iostream>

using namespace std;

int main()
{
int n;
int p[20];
(cin>>n);
if(n<20)
{
int a,b,c;

for(int i=0; i<n; i++)
{
cin>>a>>b>>c;
if( a<1000 || a>10000 || b<1000 || b>10000 || c<1000 || c>10000 )
return -1;
if(a>=b && a<=c )
(p[i]=a);
else if( a>=c && a<=b )
p[i] =a;
else if(b>=a && b<=c )
(p[i] =b);
else if( b>=c && b<=a )
(p[i] =b);
else  if(c>=b && c<=a )
(p[i] =c);
else if( c>=a && c<=b )
(p[i] =c);
}
for(int i=0; i<n; i++ )
cout<<"\nCase "<<i<<":"<<p[i];

}
return 1;
}

``````

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11727 - Cost Cutting

Always return 0. Your output must be completely same as sample output. Change line

Code: Select all

``cout<<"\nCase "<<i<<":"<<p[i];``
It must be

Code: Select all

``cout<<"Case "<< i + 1 <<": "<<p[i]<<endl;``
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

tamal_5th_gen
New poster
Posts: 2
Joined: Mon Nov 16, 2015 3:20 pm

### Re: 11727 - Cost Cutting

what is the problem in this code

Code: Select all

``````#include<iostream>
using namespace std;

int main()
{
int a,b,c,t,i;
cin>>t;
for(i=0; i<t; i++)
{
int mid;
cin>>a>>b>>c;

if(a>b)
{
if(a>c)
{
if(b>c)
{
mid=b;
}
else
{
mid=c;
}
}
else
{
mid=a;
}
}
else
{
if(b>c)
{
if(c>a)
{
mid=c;
}
else
{
mid=a;
}
}
else
{
mid=b;
}
}
cout<<"case "<<i+1<<": "<<mid<<endl;

}
return 0;
}``````