Professional Documents
Culture Documents
import java.util.Scanner;
Answer.2
import java.util.*;
class Decipher2
{
Scanner sc=new Scanner(System.in);
String str;
String[] code;
int count=1;
char[] defaultChar= {'c','d','a','e','l','i','m','o','u','v'};
Decipher2()
{
str=sc.nextLine();
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)==' ')
count++;
}
code=new String[count];
Arrays.fill(code, "");
}
void decipher()
{
int i=0,j=0,k=0, wd=0;
while(i<str.length())
{
if(str.charAt(i)==' ')
{
i++;
code[j]+=" ";
j++;
}
wd =(int)str.charAt(i);
k=wd-48;
code[j]+=defaultChar[k];
i++;
}
for(j=0;j<code.length;j++)
{
System.out.print(code[j]);
}
}
}
public class dec2
{
public static void main(String[] args)
{
Decipher2 obj= new Decipher2();
obj.decipher();
}
}
Answer.3
import java.util.Scanner;
import java.util.*;
import java.util.Scanner;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Scanner;
int result = 0;
for (int i = 0; i < s.length(); i++) {
int current = map.get(s.charAt(i));
int next = (i < s.length() - 1) ? map.get(s.charAt(i + 1)) : 0;
if (current < next) {
result += next - current;
i++;
} else {
result += current;
}
}
return result;
}
import java.util.Scanner;