All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
jddantes
Learning poster
Posts: 73 Joined: Sat Mar 08, 2014 8:55 am
Post
by jddantes » Wed Apr 30, 2014 8:26 am
Hello, I keep on getting WA. I've tried all the input in this thread
Code: Select all
#include <stdio.h>
int main(){
while(1){
int h,u,d,f;
scanf("%d %d %d %d",&h,&u,&d,&f);
if(!h)
return 0;
f*=u;
h*=100;
u*=100;
d*=100;
int day = 0;
int good = 0;
int pos = 0;
while(1){
day++;
if(u<0)
u = 0;
pos += u;
if(pos>h){
good = 1;
break;
}
u-=f;
pos-=d;
if(pos < 0)
break;
}
if(good)
printf("sucess ");
else
printf("failure ");
printf("on day %d\n",day);
}
return 0;
}
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Thu May 01, 2014 12:03 am
success not sucess
Check input and AC output for thousands of problems on
uDebug !
mratan16
New poster
Posts: 21 Joined: Fri May 16, 2014 12:36 am
Post
by mratan16 » Wed Aug 20, 2014 1:02 pm
Hi a friend asked me to check his code and was wondering why it was wrong. I tried but could not find fault in it. Can you guys help?
Code: Select all
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double h, u, d, f;
cin >> h >> u >> d >> f;
if ((h == 0) || !(1 <= h <= 100) || !(1 <= u <= 100) || !(1 <= d <= 100) || !(1 <= f <= 100)){
return 0;
}
/* h is where it starts, u is how much it moves, d is the constant it slides down,
and f is the percentage that u is reduced by the next day */
double i, s; // i is the day, s is the snail's current height which is 0
i = 0;
s = 0;
while (true){
i ++; // dawn of the first day which will then keep going
s += u; // adding to the height
if (s > h){
cout << "success on day " << i << endl;
return 0;
}
s -= d; // it is now night, snail slides down
if (s < 0){
cout << "failure on day " << i << endl;
return 0;
}
u -= u * (f/100); // fatigue
cout << s << "," << h << "," << i << endl;
}
}
Thank you very much! .
lighted
Guru
Posts: 587 Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek
Post
by lighted » Wed Aug 20, 2014 4:56 pm
Doesn't match sample I/O.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
mratan16
New poster
Posts: 21 Joined: Fri May 16, 2014 12:36 am
Post
by mratan16 » Thu Aug 21, 2014 12:11 pm
Thanks again lighted. But I was wondering why?
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Thu Aug 21, 2014 8:16 pm
The input file contains one or more test cases
Your code is only reading one test case and is printing extra stuff.
Check input and AC output for thousands of problems on
uDebug !
mratan16
New poster
Posts: 21 Joined: Fri May 16, 2014 12:36 am
Post
by mratan16 » Fri Aug 22, 2014 12:47 am
Thanks a lot but would you know why it also fails on test cases?
brianfry713
Guru
Posts: 5947 Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA
Post
by brianfry713 » Tue Aug 26, 2014 7:48 pm
If you know a test case that the code fails on, and you know what the output should be, then look at your code step by step and figure out where it is wrong.
Check input and AC output for thousands of problems on
uDebug !
gautamzero
New poster
Posts: 32 Joined: Fri Oct 10, 2014 1:10 pm
Location: Sylhet, Bangladesh
Post
by gautamzero » Sat Dec 20, 2014 10:58 pm
WA ???
Last edited by
gautamzero on Sun Dec 21, 2014 9:39 am, edited 1 time in total.
None but a fool is always right..
so don't be upset when u r wrong..
lighted
Guru
Posts: 587 Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek
Post
by lighted » Sun Dec 21, 2014 9:34 am
Input
Code: Select all
1 100 100 100
100 1 100 100
100 1 100 1
0 0 0 0
Acc Output
Code: Select all
success on day 1
failure on day 1
failure on day 1
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
gautamzero
New poster
Posts: 32 Joined: Fri Oct 10, 2014 1:10 pm
Location: Sylhet, Bangladesh
Post
by gautamzero » Sun Dec 21, 2014 9:40 am
what a silly mistake!!
thnx lighted
None but a fool is always right..
so don't be upset when u r wrong..
juan321
New poster
Posts: 2 Joined: Sat Jan 23, 2016 1:43 am
Post
by juan321 » Sat Jan 23, 2016 1:47 am
I have problems with some cases Help D:
success on day 4
failure on day 3
failure on day 7
failure on day 68
success on day 21
failure on day 1
Zyaad Jaunnoo
Experienced poster
Posts: 122 Joined: Tue Apr 16, 2002 10:07 am
Post
by Zyaad Jaunnoo » Fri Jan 29, 2016 6:36 pm
juan321 wrote: I have problems with some cases Help D:
success on day 4
failure on day 3
failure on day 7
failure on day 68
success on day 21
failure on day 1
Hello Juan,
Can you please post your code?
Kinleyperker
New poster
Posts: 1 Joined: Mon Jan 18, 2016 8:18 am
Post
by Kinleyperker » Wed Feb 17, 2016 11:29 am
Can anyone help me with this code...It's getting WA
#include<stdio.h>
int main()
{
int H=1, U, D, F, x;
float s, v, w;
while(H>0)
{
scanf("%d %d %d %d", &H, &U, &D, &F);
w = U*F;
if(H>0)
{
s = 0.00;
for(x=0; ; x++)
{
if(x) v = v - (w/100);
else if(!x) v = U;
s = s + v;
if(s>H)
{
printf("success on day %d\n", x+1);
break;
}
s = s - D;
if(s<0)
{
printf("failure on day %d\n", x+1);
break;
}
}
}
}
return 0;
}
prakashn27
New poster
Posts: 1 Joined: Sat Mar 19, 2016 12:21 am
Post
by prakashn27 » Sat Mar 19, 2016 12:28 am
Hi can anyone help me with this code. I am getting wrong answer for a test case. Problem:
573 - The Snail
Code: Select all
int main() {
int h, u, d, f;
cin >> h;
while(h != 0) {
cin >> u >> d >> f;
//cout << "inputs are " << h << u << d << f << endl;
float initial_ht = 0.0, dist_climbed = (float)u, height_after_climbing = 0.0, height_after_sliding = 0.0;
float depeciation_each_day = (float)u * f / 100;
//cout << "depre each day " << depeciation_each_day << endl;
int i = 1;
bool is_success = true;
for(i = 1; height_after_sliding < h; i++) {
initial_ht = height_after_sliding;
cout << initial_ht ;
if(i != 1) {
dist_climbed -= depeciation_each_day;
}
height_after_climbing = initial_ht + dist_climbed;
if (height_after_climbing > h) {
break;
}
if(height_after_climbing < 0) {
is_success = false;
break;
}
height_after_sliding = height_after_climbing - (float)d;
initial_ht = height_after_sliding;
cout << " " << dist_climbed << " " << height_after_climbing << " " << height_after_sliding << endl;
}
if(!is_success) {
cout << "failure on day ";
} else {
cout << "success on day ";
}
cout << i << endl;
cin >> h;
}
}
Input:
Expected output:
Output i get is:
Thanks a lot in advance.