Reverse Rot: Difference between revisions
Jump to navigation
Jump to search
imported>Ww109 Created page with "[http://speedyguy17.info/data/mcpc/mcpc2014/rot/rot.html Original Description] == Idea == Manipulate ASCII Numbers Handle special cases by moving them to end of normal cases..." |
imported>Kmk21 No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[http://speedyguy17.info/data/mcpc/ | [http://speedyguy17.info/data/mcpc/mcpc2013/mcpc2013/pdfs/C%20Missing%20Pages.pdf Original Description] | ||
== Idea == | == Idea == | ||
Manipulate ASCII | Manipulate the ASCII value of chars | ||
Handle special cases | Handle special cases of moving them to the end of normal ones. Then use module to get the result after shift | ||
== Code == | |||
<syntaxhighlight line lang="java"> | |||
== Code == import java.util.*; | import java.util.*; | ||
public class Reverse_Rot { | public class Reverse_Rot { | ||
Line 38: | Line 38: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:mcpc2014]] | |||
[[Category:ICPC Problems]] | [[Category:ICPC Problems]] | ||
[[Category:Implementation Easy]] | [[Category:Implementation Easy]] | ||
[[Category:Algorithm | [[Category:Algorithm Trivial]] | ||
[[Category:ASCII]] |
Latest revision as of 19:48, 13 January 2016
Idea
Manipulate the ASCII value of chars
Handle special cases of moving them to the end of normal ones. Then use module to get the result after shift
Code
import java.util.*;
public class Reverse_Rot {
public static void encrypt(String s, int k){
for(int i = s.length()-1; i>=0; i--){
char c = s.charAt(i);
if(c == 95) c = 91;
if(c == 46) c = 92;
c = (char)(c + k);
c = (char)((c - 'A') % 28 + 'A');
if(c == 91) c = 95;
if(c == 92) c = 46;
System.out.print(c);
}
System.out.println();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
int k = scan.nextInt();
if(k == 0)
break;
String s = scan.next();
encrypt(s,k);
}
}
}