Thank u guys for participating in challenge questions....
here the two solution given by shubham gulati(in java) & abhishek kumar (in c++)
--------------------------------------------------------------------------------------------------------------------------
here the two solution given by shubham gulati(in java) & abhishek kumar (in c++)
in c++
#include<iostream> #include<conio.h> #include<stdlib.h> #include<string> #include<sstream> using namespace std; main(){ system("cls"); string name,name2; int n1=0,n2=0; int len; stringstream convert; cout<<"Enter encrypted text:"; getline(cin,name); for(len=0;name[len];len++); if(len>2){ convert<<name.substr(len-2); convert>>n1; convert.clear(); convert<<name.substr(len-3); convert>>n2; char temp='a'; int c=0; if(n1>=48&&n1<=57){ temp=(char)n1; c=2; } else if(n1>=97&&n1<=99){ temp=(char)n1; c=2; } else if(n2>=100&&n2<=122){ temp=(char)n2; c=3; } name2=name.substr(0,len-c); name2+=temp; cout<<name2<<endl; int len2; for(len2=0;name2[len2];len2++); int i; for(i=0;i<len2/2;i++){ if(name2[i]<123&&name2[i]>96) name2[i]=97+(25-(name2[i]-97)); else if(name2[i]>=48&&name2[i]<=57){ if((name2[i]-48)<=4) name2[i]=name2[i]+5; else name2[i]=name2[i]-5; } } for(;i<len2-1;i++){ if(name2[i]<=110&&name2[i]>97) name2[i]--; else if(name2[i]>110&&name2[i]<123) name2[i]++; else if(name2[i]>=48&&name2[i]<=57){ if((name2[i]-48)<=4) name2[i]=name2[i]+5; else name2[i]=name2[i]-5; } } cout<<name2; } else{ int n3=0; convert<<name; convert>>n3; cout<<(char)n3; } }
in java
package java_programs;
import java.util.Scanner;
public class Enc {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("enter en code");
Scanner scan = new Scanner(System.in);
String name=scan.nextLine();
int len,i,cutting,half=2;
char[] newname = name.toCharArray();
len=newname.length;
if(len>0 && len<=2){
int f=(int)(newname[0])-48;
f=(f*10)+(newname[1])-48;
System.out.println((char)f);
}
else if(len>2){
if(len<2)
half=1;
String c=name.substring(len-3);
System.out.println(c);
int f=(int)(newname[len-3])-48;
f=(f*10)+(newname[len-2])-48;
f=(f*10)+(int)(newname[len-1]) -48;
if(f>=97 && f<=122 || f>=48 && f<=57)
cutting=3;
else {
f=(int)(newname[len-2])-48;
f=(f*10)+(newname[len-1])-48;
//f=(f*10)+(int)(newname[len- 1])-48;
cutting=2;
}
for(i=0; i<(len-half)/2; i++)
{
if(newname[i]<123&&newname[i]> 96)// a to z
newname[i]=(char)(97+(25-( newname[i]-97)));
else if(newname[i]>=48&&newname[i]< =57)// 1 to 9
{
if((newname[i]-48)<=4)
newname[i]=(char)(newname[i]+ 5);
else
newname[i]=(char)(newname[i]- 5);
}
}
for(; i<len-cutting; i++)
{
if(newname[i]<=(97+13)&& newname[i]>97)
newname[i]--;
else if(newname[i]>(97+13)&& newname[i]<123)
newname[i]++;
else if(newname[i]>=48&&newname[i]< =57)
{
if((newname[i]-48)<=4)
newname[i]=(char)(newname[i]+ 5);
else
newname[i]=(char)(newname[i]- 5);
}
}
newname[len-cutting]=(char)f;
System.out.println(f);
int j;
for(j=0; j<len-cutting+1; j++)
System.out.print(newname[j]);
}
}
}
import java.util.Scanner;
public class Enc {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("enter en code");
Scanner scan = new Scanner(System.in);
String name=scan.nextLine();
int len,i,cutting,half=2;
char[] newname = name.toCharArray();
len=newname.length;
if(len>0 && len<=2){
int f=(int)(newname[0])-48;
f=(f*10)+(newname[1])-48;
System.out.println((char)f);
}
else if(len>2){
if(len<2)
half=1;
String c=name.substring(len-3);
System.out.println(c);
int f=(int)(newname[len-3])-48;
f=(f*10)+(newname[len-2])-48;
f=(f*10)+(int)(newname[len-1])
if(f>=97 && f<=122 || f>=48 && f<=57)
cutting=3;
else {
f=(int)(newname[len-2])-48;
f=(f*10)+(newname[len-1])-48;
//f=(f*10)+(int)(newname[len-
cutting=2;
}
for(i=0; i<(len-half)/2; i++)
{
if(newname[i]<123&&newname[i]>
newname[i]=(char)(97+(25-(
else if(newname[i]>=48&&newname[i]<
{
if((newname[i]-48)<=4)
newname[i]=(char)(newname[i]+
else
newname[i]=(char)(newname[i]-
}
}
for(; i<len-cutting; i++)
{
if(newname[i]<=(97+13)&&
newname[i]--;
else if(newname[i]>(97+13)&&
newname[i]++;
else if(newname[i]>=48&&newname[i]<
{
if((newname[i]-48)<=4)
newname[i]=(char)(newname[i]+
else
newname[i]=(char)(newname[i]-
}
}
newname[len-cutting]=(char)f;
System.out.println(f);
int j;
for(j=0; j<len-cutting+1; j++)
System.out.print(newname[j]);
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
0 comments:
Post a Comment