+ 29
Does anyone understand the problem Halloween Candy ?
62 Respuestas
+ 32
Am trying with C++
The main formula i made is
round(200/houses)
I passed 2 tests but failed next 3.
Whats the matter?
+ 22
Explanation :
The problem states that all the houses you and your friends visit gives candy except 3 houses, among these 3 houses, 1 house give toothbrushes and 2 houses gives dollar.
Also the output must "round up" not "round figure or approximate", which means if 20.1 is the output then the "round up" is 21 not 20.
Example explanation:
If you and your friends visit 10 houses then 7 houses gives candy, 1 house gives toothbrushes and remaining 2 houses gives dollar.
"""
Code by "Shivaneeth P"
Python code
"""
import math
houses = int(input())
#probability of dollar per one house
probability_dollar=2.0/houses
#percentage of dollar for all houses
percentage_dollar = probability_dollar * 100.0
#rounding up value
print(math.ceil(percentage_dollar))
+ 18
That is because if you use round there is a problem
Round(2.5)=2
try with ceil 😉
+ 12
Chances=(2 bills/total houses)*100
The problem is... how can i round that number?
+ 8
This is my Halloween candy solution in C++...
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double houses, percent;
cin >> houses;
percent = 2 / houses;
percent = ceil(percent * 100);
if (percent == (int)percent )
{
cout << (int)percent ;
}
else
cout << (int)percent + 1;
//your code goes here
return 0;
}
+ 7
#include <stdio.h>
int main() {
int houses,c;
scanf("%d", &houses);
c=200/houses;
if(200%houses==0)
printf("%d",c);
else
printf("%d",c+1);
return 0;
}
This works fine..
+ 6
I'm stuck there too.. failed in 3 last cases
+ 5
Coder Kitten But as each house gives one candy ! doesnt it make four candies from four houses ?
+ 4
I am not understanding this question, can anyone explain this question briefly?
+ 4
My solution :
#include<iostream>
using namespace std;
int main ()
{
int n; cin>>n;
int d = 200/n;
cout<< (200%n?d+1:d);
return 0;
}
+ 3
Coder Kitten thanks 200.0 worked. Now I got that 200 and 200.0 are different
David Martínez
#include <cmath>
float x = round(200.0/houses);
That's how I rounded it and it worked.
+ 2
Sarthak Gupta how do you round the number?
+ 2
I failed in three last cases.
Somebody has the spec that those cases? I am not a pro member.
Please send me a email to: *redacted*
Have a nice day!
+ 2
undefinedGalaxy
There's no need to do that.
Updated code!
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double houses, percent;
cin >> houses;
percent = 2 / houses;
percent = ceil(percent * 100);
/*
if (percent == (int)percent )
{
cout << (int)percent ;
}
else*/
cout << (int)percent ;
//your code goes here
return 0;
}
+ 2
Can someone please explain me the question i don't get it
+ 2
Hello,
My code in Python below. I didn't use any special functions like round. Just compare int and float results.
houses = int(input())
dolar=200.0/houses
if dolar==int(dolar):
print(int(dolar))
else: print(int(dolar+1))
+ 2
I passed first two cases but left three did'nt
+ 2
Here is in C++
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int houses;
cin>>houses;
double percent =200;
//your code goes here
if(houses>=3){
percent /=houses;
cout<<ceil(percent);
}
return 0;
}
+ 1
I was about to do it, but I got my head wrapped on the "army time" one.
I read its description and it was a bit confusing, tho.
If I happen to do the halloween one tomorrow, I'll try to share the experience.
+ 1
I failed in three last cases.
Somebody has the spec of those cases? I am not a pro member.
I think it is because we should consider what happens if the user introduces a invalid value, for example a float, because the problem must receive a integer.
I guess, I do not know xD