given below code is for games spoj or how many games spoj.
simpe logic behind this is we can write a fraction number into its lowest fraction and we have to just print denominator .
eg:
lets take 5.5 now we can write this as 55/10 now we calculate the gcd of 55 and 10 which is 5 and then divide the denominator by 5. and thats the answer
simpe logic behind this is we can write a fraction number into its lowest fraction and we have to just print denominator .
eg:
lets take 5.5 now we can write this as 55/10 now we calculate the gcd of 55 and 10 which is 5 and then divide the denominator by 5. and thats the answer
#include <stdio.h> #include <cmath> #include <string> #include <iostream> using namespace std; long gcd(long a,long b) { return b==0?a:gcd(b,a%b); } int main() { int t,count,i,flage; scanf("%d",&t); while(t--) { string s; cin>>s; long number=1,frac; count=0; flage=0; for(i=s.size()-1;i>=0;i--) { if(s[i]=='.') { flage=1; break; } else count++; } for(i=0;i<s.size();i++) { if(s[i]!='.') { number=number*10 + (s[i]-48); } } frac=1; if(flage) frac=pow(10,count); printf("%ld\n",frac/gcd(number,frac)); } return 0; }
number must be initialise to 0.
ReplyDeleteSo you are leaving any thought of recurring decimal.
ReplyDeleteAccording to this code, the answer for 0.3333 will be 10000 but it can be 4/3.
"Instant classic. Bookmark this moment!" spolszczenia
ReplyDeleteOnline slot games come in a wide variety of themes and formats.hargatoto
ReplyDeleteThis will mean you make sure you are not folding or calling too often.https://linoshirt.com/
ReplyDeleteThe Toto 4D jackpot is massive! Every time I see the prize pool, I get a little more excited about the next draw. Here’s hoping that I’ll be the one who gets lucky enough to win it! toto 4d
ReplyDeleteTrusted online betting site that is easy to win on the website GAJIAN123
ReplyDelete