My issue
for input {1 589 1 1}
it gives me output “yes” with this code:
if(u==v)
std::cout << “yes” << std::endl;
else{
float v1 = sqrt((uu) - (2a*s));
if(v<v1)
std::cout << "no" << std::endl;
else
std::cout << "yes" << std::endl;
}
}
but “no” if I do this:
if(u==v)
std::cout << “yes” << std::endl;
else{
float v1 = sqrt((uu) - (2a*s));
if(v1<v)
std::cout << "yes" << std::endl;
else
std::cout << "no" << std::endl;
}
}
I think both should give same output because they are mostly same except of “if” conditions. I am a beginner and I can’t understand what is the difference
My code
#include <iostream>
#include <cmath>
using namespace std;
void soln(){
float u,v,a,s;
std::cin >> u>>v>>a>>s;
if(u==v)
std::cout << "yes" << std::endl;
else{
float v1 = sqrt((u*u) - (2*a*s));
if(v<v1)
std::cout << "no" << std::endl;
else
std::cout << "yes" << std::endl;
}
}
int main() {
// your code goes here
int t;
std::cin >> t;
while(t--){
soln();
}
return 0;
}
Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone