An encoded string can be decoded by finding actual character for the given ASCII code in the encoded message. Write a program to input anencoded text having only
sequence of ACSII values without any spaces.Any code or value which is not in the range(65-90 or 97-122 or 32 for space) will be ignored and should not appear in the output message.Decode the encoded text and print in the form of sentence.The first alphabet of each word must be in capitals and rest alphabets will be in lower case
only. Any consecutive sets of code 32 will be taken as only one blank space.
The output should be exactly in the following format:
Input (encoded string) : 10665771011153266797868
Output(decoded string) : James Bond
Input (coded string) : 78487367421013232321006589
Output(decoded string) : Nice Day
Coding:
import java.lang.*;
class de_code
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String code=br.readLine();
int c=0;
String k="";
while(c<code.length())
{
char s=code.charAt(c);
if (s!='1')
{
String S1= code.substring(c,c+2);
int p=Integer.parseInt(S1);
char p1= (char)p;
if((p1>='a' && p1<='z')||(p1>='A' && p1<='Z')||(p1==32))
k=k+p1;
c+=2;
}
else
{
String S1= code.substring(c,c+3);
int p=Integer.parseInt(S1);
char p1= (char)p;
k=k+p1;
c+=3;
}
}
String z=k.toLowerCase();
char w=z.charAt(0);
char x=Character.toUpperCase(w);
String y=x+z.substring(1);
System.out.println(y.replaceAll("\\s+"," "));
}
}
Comment
got this !!!
ReplyDelete👍
Delete👍
DeleteThis comment has been removed by the author.
ReplyDelete