Created
May 28, 2016 07:03
-
-
Save rishiloyola/f60e6965d6917a79d5c9c6af1bca16c3 to your computer and use it in GitHub Desktop.
Games - How many games ( spoj question).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.*; | |
class Main | |
{ | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
Scanner s=new Scanner(System.in); | |
int num = s.nextInt(); | |
for(int i=0;i<num;i++){ | |
String input = s.next(); | |
if (!input.contains(".")){ | |
System.out.println(1); | |
} else { | |
String frag = input.substring(input.indexOf('.')+1); | |
int number = Integer.parseInt(frag); | |
int length = frag.length(); | |
int power = (int) Math.pow(10, length); | |
int dec = power; | |
while(dec%number!=0){ | |
dec = dec + power; | |
} | |
System.out.println(dec/number); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is this approach of multiplying the decimal part till an integer is obtained, wrong?
#include<bits/stdc++.h>
using namespace std;
int main() {
int t,int_part,num;
double n,dec_part;
cin>>t;
while(t--) {
cin>>n;
num=1;
int_part=int(n10000)/10000;
dec_part=(n-int_part);
if(dec_part!=0) {
while(1) {
float temp=dec_partnum;
int int_part_temp=int(temp*10000)/10000;
double dec_part_temp=(temp-int_part_temp);
if(dec_part_temp==0)
break;
else
num++;
}
}
cout<<num<<endl;
}
}