From 8fbc715e0796feb78c2af3bd7d7f85a681251ef8 Mon Sep 17 00:00:00 2001 From: Gustavo Higuera Date: Thu, 16 Feb 2023 10:11:38 -0600 Subject: [PATCH] add solution to cryptogram in java --- solutions/cryptopangrams/cryptopangrams.java | 82 ++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 solutions/cryptopangrams/cryptopangrams.java diff --git a/solutions/cryptopangrams/cryptopangrams.java b/solutions/cryptopangrams/cryptopangrams.java new file mode 100644 index 00000000..1e220478 --- /dev/null +++ b/solutions/cryptopangrams/cryptopangrams.java @@ -0,0 +1,82 @@ +import java.util.*; +import java.io.*; +import java.math.BigInteger; + +class Solution +{ + public static void main(String[] args) + { + Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in))); + int test = input.nextInt(); + + for (int z = 1; z <= test; z++) + { + BigInteger bigint = input.nextBigInteger(); + int l = input.nextInt(); + BigInteger[] a=new BigInteger[102]; + + for(int i=0;i s = new HashSet(); + BigInteger y; + int j=1; + BigInteger zz=a[0].gcd(a[j]); + int e=0; + + while(zz.compareTo(a[0])==0) + { + zz=a[0].gcd(a[j]); + j++; + e=1; + } + + if(e==1) j--; + BigInteger[] ans=new BigInteger[103]; + ans[j]=a[0].gcd(a[j]); + + for(int i=j;i0;i--) + { + y=ans[i]; + ans[i-1]=a[i-1].divide(y); + } + + for(int i=0;i<=l;i++) s.add(ans[i]); + Map hashMap = new HashMap<>(); + j=0; + BigInteger[] b=new BigInteger[26]; + + for (BigInteger i : s) + { + b[j]=i; + j++; + } + + Arrays.sort(b); + + for(int i=0;i<26;i++) + { + char r=(char)('A'+i); + hashMap.put(b[i],r); + } + + String s1=""; + + for(int i=0;i<=l;i++) + { + + s1+=hashMap.get(ans[i]); + } + + System.out.println("Case #" + z + ": "+s1); + } + } +}