system
November 8, 2018, 6:18pm
1
Dilu is a young boy who loves mathematics. He recently learned how to code. He was interested in sol…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
Can anyone tell me why I’m getting WA in testcase 2?
#include<stdio.h>
int main()
{
long long a, b;
int T, r, i;
scanf(“%d”, &T);
while(T–) {
scanf(“%lld%lld”, &a, &b);
printf(“%lld”, a/b);
int c[101];
for(i=0; i<100; i++) {
c[i] = 0;
}
for(i=0; i<100; i++) {
r = a % b;
a = r*10;
c[i] = a/b;
if(i==0 && r!=0) {
printf(“.”);
}
else if(r==0) {
break;
}
}
if(c[99] > 4) {
int carry = 1;
for(i=98; i>=0; i–) {
if(c[i]+carry > 9) {
c[i] = c[i]%10;
carry = (int)c[i]/10;
}
else {
c[i] = c[i]+carry;
carry = 0;
}
if(carry==0) {
break;
}
}
}
for(i=0; i<99; i++) {
if(c[i] == 0) {
int j,t = 1;
for(j=i; j<99; j++) {
if(c[j] == 0) {
t = 0;
}
else {
t = 1;
break;
}
}
if(t==1) {
printf(“%d”, c[i]);
}
else {
break;
}
}
else {
printf(“%d”, c[i]);
}
}
printf(“\n”);
}
return 0;
}
Why gettin WA?
#include<set>
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<climits>
#include<cstring>
#include<cmath>
#include<unordered_map>
#include<sstream>
#include<cmath>
#include<iomanip>
#include<numeric>
using namespace std;
int main(){
int n;
cin>>n;
while(n){
double a,b;
cin>>a>>b;
cout<<setprecision(100)<<(double)a/b<<endl;
n--;
}
}