Dilu's Library


This is a companion discussion topic for the original entry at https://toph.co/p/dilus-library

Why I’m geting WA?

/********************
Riz1 Ahmed, CSE, LU.
fb.com/riz1ahmed
Code Start Time: 2019-12-19-20.16
******************/
#include<bits/stdc++.h>
#define read freopen(“in.txt”,“r”,stdin);
#define write freopen(“out.txt”,“w”,stdout);
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long int
const ll M=1e9+7;
using namespace std;
int main(){
ll a,b,i;
scanf("%d");
while(~scanf("%lld %lld",&a,&b)){
string ans="";
ans+=to_string(a/b);
a%=b, a
=10;
ans+=’.’;
for (i=1; i<100; i++)
ans+=to_string(a/b), a%=b, a
=10;
ll x=a/b; a%=b, a
=10;
if (a/b>4) x++;
ans+=to_string(x);
while(ans.back()==‘0’) ans.pop_back();
if (ans.back()==’.’) ans.pop_back();
cout<<ans<<endl;
}
return 0;
}

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--;
	}
}