exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
⌀ | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
sequencelengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
⌀ | difficulty
int64 -1
3.5k
⌀ | prob_desc_output_spec
stringlengths 17
1.47k
⌀ | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | a99188f0d3af8b214326b7f8af64cff8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package solution;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author Beaudelaire HOUNDO
*/
public class Solution {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
String alphabet="abcdefghijklmnopqrstuvwxyz";
int t = in.nextInt();
for (int i = 0; i < t; i++) {
String ans="";
int n= in.nextInt();
String Code=in.next();
String CODE[]=Code.split("");
ArrayList<String> A = new ArrayList<String>(Arrays.asList(CODE));
for(int j=n; j>=1;j--){
if(A.get(j-1).equals("0")==false){
int tmp=Integer.parseInt(A.get(j-1));
String tmp1=Character.toString(alphabet.charAt(tmp-1));
ans= tmp1+ans;
}else{
int tmp=Integer.parseInt(A.get(j-3)+A.get(j-2));
String tmp1=Character.toString(alphabet.charAt(tmp-1) );
ans= tmp1+ans;
j=j-2;
}
}
System.out.println(ans);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c7911971fa9ffb2382479691f82b5c0b | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int caseNum = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
for (int t = 1; t <= caseNum; ++t) {
int n = in.nextInt();
String str = in.next();
StringBuilder sb = new StringBuilder();
int i = n - 1;
char[] ch = new char[]{'0','a','b','c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
while(i >= 0){
if(str.charAt(i) - '0' == 0){
char sub = ch[Integer.valueOf(str.substring(i - 2, i))];
sb.append(sub);
i-= 3;
}else{
char sub = ch[(str.charAt(i) - '0')];
sb.append(sub);
i--;
}
}
System.out.println(sb.reverse().toString());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 60cfc8811b9f6c7426b64e983b074056 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
import java.util.*;
import java.lang.*;
import java.io.*;
public class decodeString {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int q=sc.nextInt();
for(int i=0; i<q; i++){
StringBuilder st=new StringBuilder();
int n=sc.nextInt();
String temp=sc.next();
//String temp=String.valueOf(m);
int j=n-1;
while(j>=0){
if(temp.charAt(j)=='0'){
int x= Integer.valueOf(temp.substring(j-2, j))+96;
//System.out.print(x);
char y=(char) x;
st.append(String.valueOf(y));
//st.append(String.valueOf(Character.valueOf(Integer.valueOf(temp.substring(j-2, j))+96)));
j=j-3;
if(j<0) break;
}
else{
int x = Integer.valueOf(String.valueOf(temp.charAt(j)))+96;
char y=(char) x;
//System.out.println(x);
st.append(String.valueOf(y));
// st.append(a);
j-=1;
if(j<0) break;
}
}
System.out.println(String.valueOf(st.reverse()));
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 21b7c5f2ce1579c41bbfca9cf027c6ac | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class temp3 {
static String ans2(String ans) {
String a = "";
for(int i = ans.length() - 1; i>=0; i--) {
a += ans.charAt(i);
}
return a;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cha = 96;
int t = sc.nextInt();
for(int i = 0; i<t; i++) {
String ans = "";
int l = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
if(l==1) {
System.out.println((char)(cha + Integer.parseInt(s.charAt(0) + "")));
continue;
}
else if(l==2) {
System.out.print((char)(cha + Integer.parseInt(s.charAt(0) + "")));
System.out.print((char)(cha + Integer.parseInt(s.charAt(1) + "")));
System.out.println();
continue;
}
int jj = l-1;
for(int j = l-1; j>=2; j--) {
String ss = "";
if(s.charAt(j) == '0') {
ss += "" + s.charAt(j-2) + s.charAt(j-1);
// System.out.println(ss + " hello " + s.charAt(j-2) + s.charAt(j-1));
j-=2;
}
else {
ss += s.charAt(j) + "";
}
int no = Integer.parseInt(ss);
ans += (char)(cha + no);
jj = j;
}
jj--;
if(jj<0) System.out.println(ans2(ans));
else if(jj==0){
ans += (char)(cha + Integer.parseInt("" + s.charAt(jj)));
System.out.println(ans2(ans));
}
else {
ans += (char)(cha + Integer.parseInt("" + s.charAt(jj)));
jj--;
ans += (char)(cha + Integer.parseInt("" + s.charAt(jj)));
System.out.println(ans2(ans));
}
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 48c9ac65273ac65032e08ba24e754c2b | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import static java.lang.Math.*;
public class x {
static FastInput scn;
static PrintWriter out;
final static int MOD = (int) (1e9 + 7);
final static int MAX = Integer.MAX_VALUE;
final static int MIN = Integer.MIN_VALUE;
// MAIN
public static void main(String[] args) throws IOException {
scn = new FastInput();
out = new PrintWriter(System.out);
int t = 1;
t = scn.nextInt();
while (t-- > 0) {
solve();
}
out.flush();
}
private static void solve() throws IOException {
int n = scn.nextInt();
char[] c = scn.next().toCharArray();
StringBuilder sb = new StringBuilder();
Stack<Character> st = new Stack<>();
for(char ch : c){
st.add(ch);
}
while(!st.isEmpty()){
int t = st.pop()-'0';
if(t == 0){
int a = st.pop()-'0';
int b = st.pop()-'0';
int tt = b*10+a;
char ch = (char)(tt-1+'a');
sb.append(ch);
}
else{
char ch = (char)(t-1+'a');
sb.append(ch);
}
}
sb.reverse();
String ans = sb.toString();
out.println(ans);
}
// CLASSES
static class Pair implements Comparable<Pair> {
int first, second;
Pair(int first, int second) {
this.first = first;
this.second = second;
}
Pair(Pair o) {
this.first = o.first;
this.second = o.second;
}
public int compareTo(Pair o) {
return this.first - o.first;
}
}
// CHECK IF STRING IS NUMBER
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
private static boolean isLong(String s) {
try {
Long.parseLong(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
// FASTER SORT
private static void fastSort(int[] arr) {
int n = arr.length;
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void fastSort(char[] arr) {
int n = arr.length;
List<Character> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void fastSortReverse(int[] arr) {
int n = arr.length;
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list, Collections.reverseOrder());
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void fastSort(long[] arr) {
int n = arr.length;
List<Long> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void fastSortReverse(long[] arr) {
int n = arr.length;
List<Long> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list, Collections.reverseOrder());
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
// QUICK MATHS
private static void swap(int[] a,int i,int j){
int t = a[i];
a[i] = a[j];
a[j] = t;
}
private static void swap(long[] a,int i,int j){
long t = a[i];
a[i] = a[j];
a[j] = t;
}
private static void swap(char[] a,int i,int j){
char t = a[i];
a[i] = a[j];
a[j] = t;
}
private static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
private static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static long power(long a, long b) {
if (b == 0)
return 1L;
long ans = power(a, b / 2);
ans *= ans;
if ((b & 1) == 1)
ans *= a;
return ans;
}
private static int mod_power(int a, int b) {
if (b == 0)
return 1;
int temp = mod_power(a, b / 2);
temp %= MOD;
temp = (int) ((1L * temp * temp) % MOD);
if ((b & 1) == 1)
temp = (int) ((1L * temp * a) % MOD);
return temp;
}
private static int multiply(int a, int b) {
return (int) ((((1L * a) % MOD) * ((1L * b) % MOD)) % MOD);
}
private static boolean isPrime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
private static boolean isPrime(long n) {
for (long i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
// STRING FUNCTIONS
private static boolean isPalindrome(String str) {
int i = 0, j = str.length() - 1;
while (i < j)
if (str.charAt(i++) != str.charAt(j--))
return false;
return true;
}
private static String reverseString(String str) {
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString();
}
private static String sortString(String str) {
int[] arr = new int[256];
for (char ch : str.toCharArray())
arr[ch]++;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 256; i++)
while (arr[i]-- > 0)
sb.append((char) i);
return sb.toString();
}
// LONGEST INCREASING AND NON-DECREASING SUBSEQUENCE
private static int LIS(int arr[]) {
int n = arr.length;
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int idx = find1(list, arr[i]);
if (idx < list.size()) {
list.set(idx, arr[i]);
} else {
list.add(arr[i]);
}
}
return list.size();
}
private static int find1(List<Integer> list, int val) {
int ret = list.size(), i = 0, j = list.size() - 1;
while (i <= j) {
int mid = (i + j) / 2;
if (list.get(mid) >= val) {
ret = mid;
j = mid - 1;
} else {
i = mid + 1;
}
}
return ret;
}
private static int LNDS(int[] arr) {
int n = arr.length;
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int idx = find2(list, arr[i]);
if (idx < list.size()) {
list.set(idx, arr[i]);
} else {
list.add(arr[i]);
}
}
return list.size();
}
private static int find2(List<Integer> list, int val) {
int ret = list.size(), i = 0, j = list.size() - 1;
while (i <= j) {
int mid = (i + j) / 2;
if (list.get(mid) <= val) {
i = mid + 1;
} else {
ret = mid;
j = mid - 1;
}
}
return ret;
}
// DISJOINT SET UNION
private static int find(int x, int[] parent) {
if (parent[x] == x) {
return x;
}
parent[x] = find(parent[x], parent);
return parent[x];
}
private static boolean union(int x, int y, int[] parent, int[] rank) {
int lx = find(x, parent), ly = find(y, parent);
if (lx == ly) {
return true;
} else if (rank[lx] > rank[ly]) {
parent[ly] = lx;
} else if (rank[lx] < rank[ly]) {
parent[lx] = ly;
} else {
parent[lx] = ly;
rank[ly]++;
}
return false;
}
// TRIE
static class Trie {
class Node {
Node[] children;
boolean isEnd;
Node() {
children = new Node[26];
}
}
Node root;
Trie() {
root = new Node();
}
public void insert(String word) {
Node curr = root;
for (char ch : word.toCharArray()) {
if (curr.children[ch - 'a'] == null) {
curr.children[ch - 'a'] = new Node();
}
curr = curr.children[ch - 'a'];
}
curr.isEnd = true;
}
public boolean find(String word) {
Node curr = root;
for (char ch : word.toCharArray()) {
if (curr.children[ch - 'a'] == null) {
return false;
}
curr = curr.children[ch - 'a'];
}
return curr.isEnd;
}
}
// INPUT
static class FastInput {
BufferedReader br;
StringTokenizer st;
FastInput() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(nextLine());
return st.nextToken();
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
char nextCharacter() throws IOException {
return next().charAt(0);
}
String nextLine() throws IOException {
return br.readLine().trim();
}
int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
int[][] next2DIntArray(int n, int m) throws IOException {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++)
arr[i] = nextIntArray(m);
return arr;
}
long[] nextLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = nextLong();
return arr;
}
long[][] next2DLongArray(int n, int m) throws IOException {
long[][] arr = new long[n][m];
for (int i = 0; i < n; i++)
arr[i] = nextLongArray(m);
return arr;
}
List<Integer> nextIntList(int n) throws IOException {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(nextInt());
return list;
}
List<Long> nextLongList(int n) throws IOException {
List<Long> list = new ArrayList<>();
for (int i = 0; i < n; i++)
list.add(nextLong());
return list;
}
char[] nextCharArray(int n) throws IOException {
return next().toCharArray();
}
char[][] next2DCharArray(int n, int m) throws IOException {
char[][] mat = new char[n][m];
for (int i = 0; i < n; i++)
mat[i] = nextCharArray(m);
return mat;
}
}
// OUTPUT
private static void printIntList(List<Integer> list) {
for (int i = 0; i < list.size(); i++)
out.print(list.get(i) + " ");
out.println(" ");
}
private static void printLongList(List<Long> list) {
for (int i = 0; i < list.size(); i++)
out.print(list.get(i) + " ");
out.println(" ");
}
private static void printIntArray(int[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println(" ");
}
private static void print2DIntArray(int[][] arr) {
for (int i = 0; i < arr.length; i++)
printIntArray(arr[i]);
}
private static void printLongArray(long[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println(" ");
}
private static void print2DLongArray(long[][] arr) {
for (int i = 0; i < arr.length; i++)
printLongArray(arr[i]);
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 3439f4ec9a0bc06fadc486beab024dc0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class Main {
private static void solve(String s1) {
StringBuilder s = new StringBuilder();
int i = 0;
for (i = 0; i < s1.length();) {
if (i+2>=s1.length()){
s.append(s1.charAt(i));
i++;
continue;
}
int val = (s1.charAt(i) - '0') * 100 + (s1.charAt(i + 1) - '0') * 10 + (s1.charAt(i + 2) - '0');
if (val % 100 == 0) {
val = val/10;
s.append((char) (val - 1 + 'a'));
i += 3;
} else {
s.append(s1.charAt(i));
i++;
}
}
int n = s.length();
StringBuilder builder = new StringBuilder();
i = 0;
while (i < n) {
if (Character.isAlphabetic(s.charAt(i))) {
builder.append(s.charAt(i));
i++;
continue;
}
if (i + 2 < n) {
int val = (s.charAt(i) - '0') * 10 + (s.charAt(i + 1) - '0');
if (s.charAt(i + 2) != '0') {
int v = (int) s.charAt(i) - '0';
builder.append((char) (v - 1 + 'a'));
i++;
} else {
if (val <= 26 && val >= 10) {
builder.append((char) (val - 1 + 'a'));
i += 3;
}
}
} else {
int v = (int) s.charAt(i) - '0';
builder.append((char) (v - 1 + 'a'));
i++;
}
}
System.out.println(builder.toString());
}
static long calc(StringBuilder builder) {
long ans = 0;
long curr = 0;
for (int i = 0; i < builder.length(); i++) {
if (builder.charAt(i) == 'X') {
curr++;
} else {
int val = builder.charAt(i) - '0';
ans += (long) val * curr;
}
}
return ans;
}
static class BIT {
int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates
public BIT(int size) {
array = new int[size + 1];
}
/**
* Range Sum query from 1 to ind
* ind is 1-indexed
* <p>
* Time-Complexity: O(log(n))
*
* @param ind index
* @return sum
*/
public int rsq(int ind) {
assert ind > 0;
int sum = 0;
while (ind > 0) {
sum += array[ind];
//Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number
ind -= ind & (-ind);
}
return sum;
}
/**
* Range Sum Query from a to b.
* Search for the sum from array index from a to b
* a and b are 1-indexed
* <p>
* Time-Complexity: O(log(n))
*
* @param a left index
* @param b right index
* @return sum
*/
public int rsq(int a, int b) {
assert b >= a && a > 0 && b > 0;
return rsq(b) - rsq(a - 1);
}
/**
* Update the array at ind and all the affected regions above ind.
* ind is 1-indexed
* <p>
* Time-Complexity: O(log(n))
*
* @param ind index
* @param value value
*/
public void update(int ind, int value) {
assert ind > 0;
while (ind < array.length) {
array[ind] += value;
//Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number
ind += ind & (-ind);
}
}
public int size() {
return array.length - 1;
}
}
public static void main(String[] args) throws FileNotFoundException {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
String s = sc.next();
solve(s);
}
}
static <T> void shuffleArray(T[] ar) {
// If running on Java 6 or older, use `new Random()` on RHS here
Random rnd = ThreadLocalRandom.current();
for (int i = ar.length - 1; i > 0; i--) {
int index = rnd.nextInt(i + 1);
// Simple swap
T a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
FastScanner() throws FileNotFoundException {
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long[] readArrayLong(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int[] readArrayInt(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
// 1 2 3 | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b37825fd860dfcf4cc5dc4e207246fec | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class B
{
public static void main(String[] args) {
FastReader sobj = new FastReader();
int t = sobj.nextInt();
while(t-- > 0)
{
int n = sobj.nextInt();
String str = sobj.nextLine();
// str = str.trim();
String ans = "";
for(int i = n-1; i >= 0; i--)
{
char ch = str.charAt(i);
if(ch == '0')
{
ans = (char)(96+Integer.parseInt(str.substring(i-2, i))) + ans;
i -= 2;
}
else
{
ans = (char)(96+Integer.parseInt(ch+"")) + ans;
}
}
System.out.println(ans);
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
/*
9 6 315045
4
1100
7
1213121
6
120120
18
315045615018035190
7
1111110
7
1111100
5
11111
4
2606
*/ | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 5e877799543c04465b8b87db90254725 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // LARGEST SQUARE
// package com.company
/*
* @author :: Yuvraj Singh
* CS UNDERGRAD AT IT GGV BILASPUR
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.out;
public class Main {
// Solution here
void solve() {
int n = in.nextInt();
char[] s= in.next().toCharArray();
String ans = "";
Stack<Character> st = new Stack<>();
for(int i=0;i<n;i++){
st.push(s[i]);
}
while(!st.empty()){
int k =st.peek()-'0';
st.pop();
if(k !=0){
ans += (char)(k - 1 + 'a');
}
else{
int aa= st.peek()-'0';
st.pop();
int a=st.peek()-'0';
st.pop();
int k1 = a*10+aa;
ans += (char)(k1 - 1 + 'a');
}
}
StringBuffer ans1 = new StringBuffer();
ans1.append(ans);
sb.append(ans1.reverse()).append("\n");
}
void start(){
sb= new StringBuffer();
int t= in.nextInt();
for(int i=1;i<=t;i++) {
solve();
}
out.print(sb);
}
// Starter Code
FastReader in;
StringBuffer sb;
public static void main(String[] args) {
new Main().run();
}
void run(){
in= new FastReader();
start();
}
long nCr(int n, int r) {
if (r > n)
return 0;
long m = 1000000007;
long[] inv = new long[r + 1];
inv[0] = 1;
if(r+1>=2)
inv[1] = 1;
for (int i = 2; i <= r; i++) {
inv[i] = m - (m / i) * inv[(int) (m % i)] % m;
}
long ans = 1;
for (int i = 2; i <= r; i++) {
ans = (int) (((ans % m) * (inv[i] % m)) % m);
}
for (int i = n; i >= (n - r + 1); i--) {
ans = (int) (((ans % m) * (i % m)) % m);
}
return ans;
}
int lower_bound(ArrayList<Integer> a, int x) { // x is the target value or key
int l=-1,r=a.size();
while(l+1<r) {
int m=(l+r)>>>1;
if(a.get(m)>=x) r=m;
else l=m;
}
return r;
}
void bubbleSort(int[] arr){
int n= arr.length;
for(int i=n-1; i>0; i--){
for(int j=0; j<i; j++){
if(arr[i] < arr[j]){
swap(arr, i, j);
}
}
}
}
void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
long numberOfWays(long n, long k) {
// Base Cases
if (n == 0)
return 1;
if (k == 0)
return 1;
if (n >= (int)Math.pow(2, k)) {
int curr_val = (int)Math.pow(2, k);
return numberOfWays(n - curr_val, k)
+ numberOfWays(n, k - 1);
}
else
return numberOfWays(n, k - 1);
}
boolean palindrome(String s){
int i=0, j= s.length()-1;
while(i<j){
if(s.charAt(i)!=s.charAt(j)) return false;
i++; j--;
}
return true;
}
int call(int[] A, int N, int K) {
int i = 0, j = 0, sum = 0;
int maxLen = Integer.MIN_VALUE;
while (j < N) {
sum += A[j];
if (sum < K) {
j++;
}
else if (sum == K) {
maxLen = Math.max(maxLen, j-i+1);
j++;
}
else if (sum > K) {
while (sum > K) {
sum -= A[i];
i++;
}
if(sum == K){
maxLen = Math.max(maxLen, j-i+1);
}
j++;
}
}
return maxLen;
}
int largestNum(int n)
{
int num = 0;
// Iterate through all possible values
for (int i = 0; i <= 32; i++)
{
// Multiply the number by 2 i times
int x = (1 << i);
if ((x - 1) >= n)
num = (1 << i) - 1;
else
break;
}
// Return the final result
return num;
}
static boolean isPrime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
// Useful Functions
// void swap(int[] arr, int i , int j) {
// int tmp = arr[i];
// i = j;
// j = tmp;
// }
int call(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MIN_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = max(call(i+1, j, mat, dp), call(i, j+1, mat, dp)) + mat[i][j];
}
int util(int i,int j, int[][] mat, int[][] dp){
int m= mat.length;
int n= mat[0].length;
if(i>=m || j>=n){
return Integer.MAX_VALUE;
}
if(i==m-1 && j==n-1){
return mat[i][j];
}
if(dp[i][j] != -1){
return dp[i][j];
}
return dp[i][j] = min(util(i+1, j, mat, dp), util(i, j+1, mat, dp)) + mat[i][j];
}
long power(long x, long y, long p) {
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int lower_bound(long[] a, long x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
int upper_bound(ArrayList<Integer> arr, int key) {
int i=0, j=arr.size()-1;
if(j==-1){
return 0;
}
if (arr.get(j)<=key) return j+1;
if(arr.get(i)>key) return i;
while (i<j){
int mid= (i+j)/2;
if(arr.get(mid)<=key){
i= mid+1;
}else{
j=mid;
}
}
return i;
}
void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
int[] intArr(int n){
int[] res= new int[n];
for(int i=0;i<n;i++){
res[i]= in.nextInt();
}
return res;
}
long[] longArr(int n){
long[] res= new long[n];
for(int i=0;i<n;i++){
res[i]= in.nextLong();
}
return res;
}
// // sieve of eratosthenes code for precomputing whether numbers are prime or not up to MAX_VALUE
long MAX= 100000000;
int[] precomp;
void sieve(){
long n= MAX;
precomp = new int[(int) (n+1)];
boolean[] prime = new boolean[(int) (n+1)];
for(int i=0;i<=n;i++)
prime[i] = true;
for(long p = 2; p*p <=n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[(int) p])
{
// Update all multiples of p
for(long i = p*p; i <= n; i += p)
prime[(int) i] = false;
}
}
// Print all prime numbers
for(long i = 2; i <= n; i++)
{
if(prime[(int) i])
precomp[(int) i]= 1;
}
}
long REVERSE(long N) {
// code here
long rev=0;
long org= N;
while (N!=0){
long d= N%10;
rev = rev*10 +d;
N /= 10;
}
return rev;
}
long sumOfDigits(String n){
long sum= 0;
for (char c: n.toCharArray()){
sum += Integer.parseInt(String.valueOf(c));
}
return sum;
}
long[] revArray(long[] arr) {
int n= arr.length;
int i=0, j=n-1;
while (i<j){
long temp= arr[i];
arr[i]= arr[j];
arr[j]= temp;
i++;
j--;
}
return arr;
}
long gcd(long a, long b){
if (b==0)
return a;
return gcd(b, a%b);
}
long lcm(long a,long b){
return (a*b)/gcd(a,b);
}
static class Pair implements Comparable<Pair>{
long first;
long second;
Pair(long x, long y){
this.first=x;
this.second=y;
}
@Override
public int compareTo(Pair o) {
return 0;
}
}
// static class Compare {
// static void compare(ArrayList<Pair> arr, int n) {
// arr.sort(new Comparator<Pair>() {
// @Override
// public int compare(Pair p1, Pair p2) {
// return (int) (p2.first - p1.first);
// }
// });
// }
// }
public static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st==null || !st.hasMoreElements()){
try{
st=new StringTokenizer(br.readLine());
}catch (Exception e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
float nextFloat(){
return Float.parseFloat(next());
}
String nextLine(){
String str="";
try{
str=br.readLine();
}catch (Exception e){
e.printStackTrace();
}
return str;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ce45285a429fcfbd9397225db79c5465 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
// Working program with FastReader
// Java program to sort hashmap by values
import java.io.*;
import java.util.stream.Collectors.*;
import java.util.*;
import java.util.stream.*;
import java.util.stream.Collectors;
public class Codeforces {
static final FastReader in = new FastReader();
static final PrintWriter out = new PrintWriter(System.out, true);
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//MAIN MAIN MAIN MAIN
public static void main(String[] args) throws IOException {
StringBuffer sb=new StringBuffer();
HashMap<Integer,Character>map=new HashMap<Integer,Character>();
for(int i=1;i<=26;i++){
map.put(i,(char)('a'+i-1));
}
// System.out.println(map);
int t=i();
while(t-->0){
int n=i();
char s[]=in.nextLine().toCharArray();
// for(int i=0;i<n;i++)System.out.print(s[i]);
StringBuffer ans=new StringBuffer();
int i=n-1;
for(i=n-1;i>=1;){
int num=Character.getNumericValue(s[i]);
if(num==0){
int num1=Character.getNumericValue(s[i-1]);
int num2=Character.getNumericValue(s[i-2]);
int num3=num2*10+num1;
ans.append(map.get(num3));
i=i-3;
}
else{
int c=Character.getNumericValue(s[i]);
ans.append(map.get(c));
i--;
}
}
if(i==0){
ans.append(map.get(Character.getNumericValue(s[i])));
}
sb.append(ans.reverse()+"\n");
}
System.out.println(sb);
}
//EXTRA EXTRA
static void printno() {
System.out.println("NO");
}
static void printyes() {
System.out.println("YES");
}
public static boolean isPrime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i < Math.sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
static int[] Swap(int[] A, int i, int j) {
int temp = A[i];
A[i]=A[j];
A[j]=temp;
return A;
}
static int LCM(int x,int y) {
int a=(x*y)/findGcd(x,y);
return a;
}
static int findGcd(int x, int y)
{
if (x == 0)
return y;
return findGcd(y % x, x);
}
static int findLcm(int x, int y)
{
return (x / findGcd(x, y)) * y;
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static String S() {
return in.next();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputL(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++) {
A[i]=in.nextLong();
}
return A;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | dcb149fe3654d209ee7002ecf0109ba4 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class Competitive {
static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int t = getInt();
while(t-- > 0){
int l = getInt();
String res = "";
char[] n = rd.readLine().toCharArray();
for(int i = 0;i < n.length;i++){
char c = n[i];
if(c == '0')continue;
if(i < l-2 && n[i+2]=='0' && (i >= l-3 || n[i+3] != '0')){
int val = Integer.parseInt(c + "" + n[i+1]);
res += toString(val);
i++;
}else{
res += toString(Character.getNumericValue(c));
}
}
System.out.println(res);
}
}
static char toString(int n){
n--;
return (char)('a' + n);
}
static int getInt() throws IOException{
return toInt(rd.readLine());
}
static int toInt(String n){
return Integer.parseInt(n);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e58b6138c9cb06db5255edfb983c0522 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main(String[] args) throws IOException{
Reader s = new Reader();
Scanner sc = new Scanner(System.in);
try{
int t= s.nextInt();
while(t-->0){
int n=s.nextInt();
String str = s.readLine();
solve(n,str);
}
}catch (Exception e){
return;
}
}
public static void solve(int n,String s){
char[] ch = s.toCharArray();
StringBuilder ans = new StringBuilder();
for(int i=n-1;i>=0;i--){
if(ch[i]!='0'){
int aa= Integer.parseInt(s.charAt(i)+"") +96;
char cc = (char)aa;
ans.append(cc);
}else{
StringBuilder ss = new StringBuilder();
ss.append(ch[i-2]);
ss.append(ch[i-1]);
int aa= Integer.parseInt(ss.toString())+96;
char cc = (char)aa;
ans.append(cc);
// ans.append(Character.toChars(Integer.parseInt(ss.toString())));
i=i-2;
}
}
ans= ans.reverse();
System.out.println(ans.toString());
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 53d0b55d4276ed6358e1823ea361ef3c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
final static StringBuilder out = new StringBuilder();
final static FastReader read = new FastReader();
public static void main(String[] args) {
int t = read.nextInt();
while(t-- > 0) {
int n = read.nextInt();
String s = read.nextLine();
String ans = "";
for(int i = s.length() - 1; i >= 0;) {
int j = i - 1;
int k = i - 2;
if(s.charAt(i) == '0'){
String indexS = s.charAt(k) + "" + s.charAt(j);
int index = Integer.parseInt(indexS) - 1;
ans = (char) (97 + index) + ans;
i = k - 1;
} else {
String indexS = s.charAt(i) + "";
int index = Integer.parseInt(indexS) - 1;
ans = (char) (97 + index) + ans;
i--;
}
}
out.append(ans).append('\n');
}
System.out.print(out);
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String fileName) throws IOException {
br = new BufferedReader(new FileReader(fileName));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 78ccae368da3caeff2987cfca00ab2e8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Codeforces {
public static class fastReader {
BufferedReader br;
StringTokenizer st;
public fastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static boolean isPalindrome(String word) {
for (int i = 0; i < word.length() / 2; i++) {
if (word.charAt(i) != word.charAt(word.length() - 1 - i)) {
return false;
}
}
return true;
}
public static fastReader sc = new fastReader();
static class AreaComparator implements Comparator<List<Long>> {
public int compare(List<Long> p1, List<Long> p2) {
if (p1.get(2) > p2.get(2))
return 1;
else
return -1;
}
}
public static void main(String[] args) {
int t = sc.nextInt();
while (t-- > 0) {
solve();
}
}
public static char getChar(int no) {
int val = 96 + no;
return (char) val;
}
public static void solve() {
int l = sc.nextInt();
String n = sc.next();
List<Integer> temp = new ArrayList<>();
for (int i = 0; i < n.length(); i++) {
if (n.charAt(i) == '0') {
temp.add(i);
}
}
List<Integer> zeros = new ArrayList<>();
if (temp.size() >= 2) {
zeros.add(temp.get(0));
for (int i = 1; i < temp.size(); i++) {
int c = temp.get(i);
if (c - zeros.get(zeros.size() - 1) == 1) {
zeros.set(zeros.size() - 1, c);
} else {
zeros.add(c);
}
}
} else {
zeros = temp;
}
// System.out.println(zeros);
HashSet<Integer> set = new HashSet<>(zeros);
StringBuilder ans = new StringBuilder();
for (int i = 0; i < n.length();) {
if (set.contains(i)) {
i++;
continue;
}
if (set.contains(i + 2)) {
// is a two digit number
String t = n.charAt(i) + "" + n.charAt(i + 1);
ans.append(getChar(Integer.parseInt(t)));
i += 2;
} else {
String t = n.charAt(i) + "";
ans.append(getChar(Integer.parseInt(t)));
i += 1;
}
}
System.out.println(ans.toString());
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c8011ef67b16fb791bfac3105c8758f3 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Decode {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String skip = sc.nextLine();
String s = sc.nextLine();
String res = "";
boolean flag = false;
while (n >= 1) {
if (s.charAt(n - 1) == '0') {
flag = true;
n--;
}
if (flag) {
res = (char) (Integer.valueOf(s.substring(n - 2, n)) + 'a' - 1) + res;
n--;
flag = false;
}else {
res = (char) (Integer.valueOf(s.substring(n - 1, n)) + 'a' - 1) + res;
}
--n;
}
System.out.println(res);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | f6daedfe10ebbf6655ab40d3a14d11a4 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
static StreamTokenizer st ;
static BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
st = new StreamTokenizer(re);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
char[]s = sc.next().toCharArray();
String ans = "";
for (int i = 0 ; i < n ; i++) {
String x = String.valueOf(s[i]);
if(i+3 < n) {
if(s[i+2] == '0' && s[i+3] != '0') {
x = x + String.valueOf(s[i+1]);
ans = ans + String.valueOf((char)(96+Integer.valueOf(x)));
i+=2;
continue;
}
}
if(i+3 == n) {
if(s[i+2] == '0') {
x = x + String.valueOf(s[i+1]);
ans = ans + String.valueOf((char)(96+Integer.valueOf(x)));
i+=2;
continue;
}
}
ans = ans + String.valueOf((char)(96+Integer.valueOf(x)));
}
pw.println(ans);
}
pw.flush();
}
static int I() throws IOException {
st.nextToken();
return (int)st.nval;
}
static long L() throws IOException {
st.nextToken();
return (long)st.nval;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 02668aab2fdf9cb5846a89fc9d2b6d13 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //package MyPackage;
import java.util.*;
import java.io.*;
public class B{
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
private static int func(int i, int a[], int prev, int k, Integer dp[][])
{
if(i == a.length) return 0;
// if(dp[i][prev] != null) return dp[i][prev];
int ans = (int) (1e9);
if(a[i] >= k - prev)
ans = Math.min(ans, func(i + 1, a, a[i], k, dp));
else
{
ans = Math.min(ans, k - prev - a[i] + func(i + 1, a, k - prev, k, dp));
a[i] = k - prev;
}
return dp[i][prev] = ans;
}
public static void main(String[] args) {
try {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
StringBuilder sb = new StringBuilder();
int testCases=in.nextInt();
while(testCases-- > 0){
int n = in.nextInt();
String t = in.next();
List<Integer> al = new ArrayList<>();
for(int i = 0; i < n; i++)
{
char c = t.charAt(i);
if(c == '0')
{
if(i + 1 < n && t.charAt(i + 1) == '0')
{
al.add(i - 2 + 1);
i++;
}
else
al.add(i - 2);
}
}
int j = 0;
for(int i = 0; i < n; i++)
{
char c = t.charAt(i);
if(j < al.size() && i == al.get(j))
{
int v = Integer.parseInt(t.substring(i, i + 2));
int val = 97 + v - 1;
// System.out.println(val);
sb.append((char) val);
j++;
i += 2;
}
else
{
int val = 97 + c - '0' - 1;
// System.out.println(val);
sb.append((char) val);
}
}
sb.append("\n");
}
out.println(sb);
out.close();
} catch (Exception e) {
System.out.println(e);
return;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b8082ce9a5ef726232cddbe22a9c86d8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main { public static void main(String[] args) { new MainClass().execute(); } }
class MainClass extends PrintWriter {
MainClass() { super(System.out, true); }
boolean cases = true;
// Solution
void solveIt(int testCaseNo) {
int n = sc.nextInt();
char a[] = sc.readCharArray(n);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (a[i] - '0' <= 2 && i + 1 < n && (a[i] == '2' ? a[i + 1] - '0' <= 6 : a[i + 1] <= '9') && (i + 2 < n && a[i + 2] == '0')
&& (i + 3 >= n || a[i + 3] != '0')) {
sb.append((char) ((Integer.parseInt(a[i] + "" + a[i + 1]) - 1) + 'a'));
i += 2;
} else {
sb.append((char) (((a[i] - '0') - 1) + 'a'));
}
}
System.out.println(sb);
}
void solve() {
int caseNo = 1;
if (cases) for (int T = sc.nextInt(); T > 1; T--, caseNo++) { solveIt(caseNo); }
solveIt(caseNo);
}
void execute() {
long S = System.currentTimeMillis();
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
this.sc = new FastIO();
solve();
out.flush();
long G = System.currentTimeMillis();
sc.tr(G - S + "ms");
}
class FastIO {
private boolean endOfFile() {
if (bufferLength == -1) return true;
int lptr = ptrbuf;
while (lptr < bufferLength) {
// _|_
if (!isThisTheSpaceCharacter(inputBufffferBigBoi[lptr++])) return false;
}
try {
is.mark(1000);
while (true) {
int b = is.read();
if (b == -1) {
is.reset();
return true;
} else if (!isThisTheSpaceCharacter(b)) {
is.reset();
return false;
}
}
} catch (IOException e) {
return true;
}
}
private byte[] inputBufffferBigBoi = new byte[1024];
int bufferLength = 0, ptrbuf = 0;
private int justReadTheByte() {
if (bufferLength == -1) throw new InputMismatchException();
if (ptrbuf >= bufferLength) {
ptrbuf = 0;
try {
bufferLength = is.read(inputBufffferBigBoi);
} catch (IOException e) {
throw new InputMismatchException();
}
if (bufferLength <= 0) return -1;
}
return inputBufffferBigBoi[ptrbuf++];
}
private boolean isThisTheSpaceCharacter(int c) { return !(c >= 33 && c <= 126); }
private int skipItBishhhhhhh() {
int b;
while ((b = justReadTheByte()) != -1 && isThisTheSpaceCharacter(b));
return b;
}
private double nextDouble() { return Double.parseDouble(next()); }
private char nextChar() { return (char) skipItBishhhhhhh(); }
private String next() {
int b = skipItBishhhhhhh();
StringBuilder sb = new StringBuilder();
while (!(isThisTheSpaceCharacter(b))) {
sb.appendCodePoint(b);
b = justReadTheByte();
}
return sb.toString();
}
private char[] readCharArray(int n) {
char[] buf = new char[n];
int b = skipItBishhhhhhh(), p = 0;
while (p < n && !(isThisTheSpaceCharacter(b))) {
buf[p++] = (char) b;
b = justReadTheByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] readCharMatrix(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++) map[i] = readCharArray(m);
return map;
}
private int[] readIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
private long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
private int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = justReadTheByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if (b == '-') {
minus = true;
b = justReadTheByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = justReadTheByte();
}
}
private long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = justReadTheByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if (b == '-') {
minus = true;
b = justReadTheByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = justReadTheByte();
}
}
private void tr(Object... o) {
if (INPUT.length() != 0) System.out.println(Arrays.deepToString(o));
}
}
InputStream is;
PrintWriter out;
String INPUT = "";
final int ima = Integer.MAX_VALUE, imi = Integer.MIN_VALUE;
final long lma = Long.MAX_VALUE, lmi = Long.MIN_VALUE;
final long mod = (long) 1e9 + 7;
FastIO sc;
}
// And I wish you could sing along, But this song is a joke, and the melody I
// wrote, wrong | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 35c44c8b448538e89cbeb3cf4f4cc9c2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t!=0)
{
t--;
int len = scan.nextInt();
String s = scan.next();
char[] ch = s.toCharArray();
StringBuilder sb = new StringBuilder();
for(int i=0;i<ch.length;i++)
{
if((i+3==ch.length || (i+3<ch.length && ch[i+3]!='0')) && i+2<ch.length && ch[i+2]=='0')
{
int n1 = (ch[i]-'0')*10+(ch[i+1]-'0' );
sb.append((char)(n1+96));
i+=2;
// System.out.print("A");
}
else
{
int n1 = (ch[i]-'0');
sb.append((char)(n1+96));
//System.out.print("B");
}
// System.out.println(sb.toString());
}
System.out.println(sb.toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 89f03475021824afeeb8dd195bee714e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.*;
import javax.print.attribute.HashAttributeSet;
//import org.graalvm.compiler.phases.graph.FixedNodeProbabilityCache;
//import org.graalvm.compiler.phases.graph.FixedNodeProbabilityCache;
import java.io.*;
import java.math.*;
import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
public class Main {
private static class MyScanner {
private static final int BUF_SIZE = 2048;
BufferedReader br;
private MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
private boolean isSpace(char c) {
return c == '\n' || c == '\r' || c == ' ';
}
String next() {
try {
StringBuilder sb = new StringBuilder();
int r;
while ((r = br.read()) != -1 && isSpace((char)r));
if (r == -1) {
return null;
}
sb.append((char) r);
while ((r = br.read()) != -1 && !isSpace((char)r)) {
sb.append((char)r);
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
static class Reader{
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static long mod = (long)(1e9 + 7);
static void sort(long[] arr ) {
ArrayList<Long> al = new ArrayList<>();
for(long e:arr) al.add(e);
Collections.sort(al);
for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i);
}
static void sort(int[] arr ) {
ArrayList<Integer> al = new ArrayList<>();
for(int e:arr) al.add(e);
Collections.sort(al);
for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i);
}
static void sort(char[] arr) {
ArrayList<Character> al = new ArrayList<Character>();
for(char cc:arr) al.add(cc);
Collections.sort(al);
for(int i = 0 ;i<arr.length ;i++) arr[i] = al.get(i);
}
static long mod_mul( long... a) {
long ans = a[0]%mod;
for(int i = 1 ; i<a.length ; i++) {
ans = (ans * (a[i]%mod))%mod;
}
return ans;
}
static long mod_sum( long... a) {
long ans = 0;
for(long e:a) {
ans = (ans + e)%mod;
}
return ans;
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static void print(long[] arr) {
System.out.println("---print---");
for(long e:arr) System.out.print(e+" ");
System.out.println("-----------");
}
static void print(int[] arr) {
System.out.println("---print---");
for(long e:arr) System.out.print(e+" ");
System.out.println("-----------");
}
static boolean[] prime(int num) {
boolean[] bool = new boolean[num];
for (int i = 0; i< bool.length; i++) {
bool[i] = true;
}
for (int i = 2; i< Math.sqrt(num); i++) {
if(bool[i] == true) {
for(int j = (i*i); j<num; j = j+i) {
bool[j] = false;
}
}
}
if(num >= 0) {
bool[0] = false;
bool[1] = false;
}
return bool;
}
static long modInverse(long a, long m)
{
long g = gcd(a, m);
return power(a, m - 2);
}
static long lcm(long a , long b) {
return (a*b)/gcd(a, b);
}
static int lcm(int a , int b) {
return (int)((a*b)/gcd(a, b));
}
static long power(long x, long y){
if(y<0) return 0;
long m = mod;
if (y == 0) return 1; long p = power(x, y / 2) % m; p = (int)((p * (long)p) % m);
if (y % 2 == 0) return p; else return (int)((x * (long)p) % m); }
static class Combinations{
private long[] z; // factorial
private long[] z1; // inverse factorial
private long[] z2; // incerse number
private long mod;
public Combinations(long N , long mod) {
this.mod = mod;
z = new long[(int)N+1];
z1 = new long[(int)N+1];
z[0] = 1;
for(int i =1 ; i<=N ; i++) z[i] = (z[i-1]*i)%mod;
z2 = new long[(int)N+1];
z2[0] = z2[1] = 1;
for (int i = 2; i <= N; i++)
z2[i] = z2[(int)(mod % i)] * (mod - mod / i) % mod;
z1[0] = z1[1] = 1;
for (int i = 2; i <= N; i++)
z1[i] = (z2[i] * z1[i - 1]) % mod;
}
long fac(long n) {
return z[(int)n];
}
long invrsNum(long n) {
return z2[(int)n];
}
long invrsFac(long n) {
return z1[(int)n];
}
long ncr(long N, long R)
{ if(R<0 || R>N ) return 0;
long ans = ((z[(int)N] * z1[(int)R])
% mod * z1[(int)(N - R)])
% mod;
return ans;
}
}
static class DisjointUnionSets {
int[] rank, parent;
int n;
public DisjointUnionSets(int n)
{
rank = new int[n];
parent = new int[n];
this.n = n;
makeSet();
}
void makeSet()
{
for (int i = 0; i < n; i++) {
parent[i] = i;
}
}
int find(int x)
{
if (parent[x] != x) {
parent[x] = find(parent[x]);
}
return parent[x];
}
void union(int x, int y)
{
int xRoot = find(x), yRoot = find(y);
if (xRoot == yRoot)
return;
if (rank[xRoot] < rank[yRoot])
parent[xRoot] = yRoot;
else if (rank[yRoot] < rank[xRoot])
parent[yRoot] = xRoot;
else
{
parent[yRoot] = xRoot;
rank[xRoot] = rank[xRoot] + 1;
}
}
}
static int max(int... a ) {
int max = a[0];
for(int e:a) max = Math.max(max, e);
return max;
}
static long max(long... a ) {
long max = a[0];
for(long e:a) max = Math.max(max, e);
return max;
}
static int min(int... a ) {
int min = a[0];
for(int e:a) min = Math.min(e, min);
return min;
}
static long min(long... a ) {
long min = a[0];
for(long e:a) min = Math.min(e, min);
return min;
}
static int[] KMP(String str) {
int n = str.length();
int[] kmp = new int[n];
for(int i = 1 ; i<n ; i++) {
int j = kmp[i-1];
while(j>0 && str.charAt(i) != str.charAt(j)) {
j = kmp[j-1];
}
if(str.charAt(i) == str.charAt(j)) j++;
kmp[i] = j;
}
return kmp;
}
/************************************************ Query **************************************************************************************/
/***************************************** Sparse Table ********************************************************/
static class SparseTable{
private long[][] st;
SparseTable(long[] arr){
int n = arr.length;
st = new long[n][25];
log = new int[n+2];
build_log(n+1);
build(arr);
}
private void build(long[] arr) {
int n = arr.length;
for(int i = n-1 ; i>=0 ; i--) {
for(int j = 0 ; j<25 ; j++) {
int r = i + (1<<j)-1;
if(r>=n) break;
if(j == 0 ) st[i][j] = arr[i];
else st[i][j] = min(st[i][j-1] , st[ i + ( 1 << (j-1) ) ][ j-1 ] );
}
}
}
public long gcd(long a ,long b) {
if(a == 0) return b;
return gcd(b%a , a);
}
public long query(int l ,int r) {
int w = r-l+1;
int power = log[w];
return min(st[l][power],st[r - (1<<power) + 1][power]);
}
private int[] log;
void build_log(int n) {
log[1] = 0;
for(int i = 2 ; i<=n ; i++) {
log[i] = 1 + log[i/2];
}
}
}
/******************************************************** Segement Tree *****************************************************/
static class SegmentTree{
long[] tree;
long[] arr;
int n;
SegmentTree(long[] arr){
this.n = arr.length;
tree = new long[4*n+1];
this.arr = arr;
buildTree(0, n-1, 1);
}
void buildTree(int s ,int e ,int index ) {
if(s == e) {
tree[index] = arr[s];
return;
}
int mid = (s+e)/2;
buildTree( s, mid, 2*index);
buildTree( mid+1, e, 2*index+1);
tree[index] = gcd(tree[2*index] , tree[2*index+1]);
}
long query(int si ,int ei) {
return query(0 ,n-1 , si ,ei , 1 );
}
private long query( int ss ,int se ,int qs , int qe,int index) {
if(ss>=qs && se<=qe) return tree[index];
if(qe<ss || se<qs) return (long)(0);
int mid = (ss + se)/2;
long left = query( ss , mid , qs ,qe , 2*index);
long right= query(mid + 1 , se , qs ,qe , 2*index+1);
return min(left, right);
}
public void update(int index , int val) {
arr[index] = val;
update(index , 0 , n-1 , 1);
}
private void update(int id ,int si , int ei , int index) {
if(id < si || id>ei) return;
if(si == ei ) {
tree[index] = arr[id];
return;
}
if(si > ei) return;
int mid = (ei + si)/2;
update( id, si, mid , 2*index);
update( id , mid+1, ei , 2*index+1);
tree[index] = Math.min(tree[2*index] ,tree[2*index+1]);
}
}
/* ***************************************************************************************************************************************************/
// static MyScanner sc = new MyScanner(); // only in case of less memory
static Reader sc = new Reader();
static int TC;
static StringBuilder sb = new StringBuilder();
static PrintWriter out=new PrintWriter(System.out);
public static void main(String args[]) throws IOException {
int tc = 1;
tc = sc.nextInt();
TC = 0;
for(int i = 1 ; i<=tc ; i++) {
TC++;
// sb.append("Case #" + i + ": " ); // During KickStart && HackerCup
TEST_CASE();
}
System.out.print(sb);
}
static void TEST_CASE() {
int n = sc.nextInt();
String str = sc.next();
String ans = "";
for(int i = 0 ;i<n ; ) {
if(i <=n-3) {
if(str.charAt(i+2) == '0' && (i+3>=n ||(i+3<n && str.charAt(i+3)!='0'))) {
Integer num = Integer.parseInt((String) str.substring(i, i+2));
ans += (char)(num-1+'a');
i+=3;
}else {
ans += (char)(str.charAt(i)-'0'-1+'a');
i++;
}
}else {
ans += (char)(str.charAt(i)-'0'-1+'a');
i++;
}
// System.out.println("ji");
}
sb.append(ans+"\n");
}
}
/*******************************************************************************************************************************************************/
/**
*/
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 35cfdd9982596df8b911b36c0379d305 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class cf {
static long[] p;
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(bf.readLine());
for(int testcases = 0; testcases < t; testcases++){
int n = Integer.parseInt(bf.readLine());
String[] s = bf.readLine().split("");
StringBuilder sb = new StringBuilder();
for(int i = s.length-1; i >= 0; i--){
if(s[i].equals("0")){
sb.insert(0, Character.toString(96+Integer.parseInt(s[i-2]+s[i-1])));
i-=2;
}
else{
sb.insert(0, Character.toString(96+Integer.parseInt(s[i])));
}
}
pw.println(sb.toString());
}
pw.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | da16cf93ab9ca7e9f3b88f2cbb09b59f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class B_Decode_String
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int z=0;z<t;z++)
{
int n=sc.nextInt();
String str=sc.next();
String ans="";
for(int j=n-1; j>=0; j--) {
if(str.charAt(j)!='0') {
ans=(char)((96+str.charAt(j))-'0')+ans;
}
else {
j=j-2;
String temp=""+(char)str.charAt(j)+(char)str.charAt(j+1);
ans=(char)(96+Integer.parseInt(temp))+ans;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 75bf29bc956d43da4abe44fb23587b68 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class HelloW {
public static void main(String[] args)
{
Scanner scn = new Scanner(System.in);
if (System.getProperty("ONLINE_JUDGE") == null) {
try {
System.setOut(new PrintStream(
new FileOutputStream("output.txt")));
scn = new Scanner(new File("input.txt"));
}
catch (Exception e) {
}
}
int tc = scn.nextInt();
while(tc>0){
int n = scn.nextInt();
String t = scn.next();
System.out.println(Decode(t));
tc--;
}
}
public static String Decode(String t){
int c=1;
HashMap<Integer,String> hp = new HashMap<>();
for (char ch = 'a'; ch <= 'z'; ++ch){
hp.put(c, String.valueOf(ch));
c++;
}
StringBuilder sb = new StringBuilder();
// System.out.println(t);
for(int i=0;i<t.length();i++){
if(i+3<t.length()){
if('0'==t.charAt(i+2) && '0'!=t.charAt(i+3)){
String s= "";
char ch1 = t.charAt(i);
s+=ch1;
char ch2 = t.charAt(i+1);
s+=ch2;
// String s = ch1+ch2;
sb.append(hp.get(Integer.parseInt(s)));
i++;
i++;
}else{
char ch1 = t.charAt(i);
sb.append(hp.get(Character.getNumericValue(ch1)));
}
}
else{
if(i+2<t.length() && t.charAt(i+2)=='0'){
String s= "";
char ch1 = t.charAt(i);
s+=ch1;
char ch2 = t.charAt(i+1);
s+=ch2;
// String s = ch1+ch2;
sb.append(hp.get(Integer.parseInt(s)));
i++;
i++;
}else{
char ch1 = t.charAt(i);
sb.append(hp.get(Character.getNumericValue(ch1)));
}
}
}
return sb.toString();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 483de7d16fa69bae92aa1d410c189146 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.lang.*;
import java.io.*;
import java.util.*;
public class codeforces {
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner();
int ttt = sc.nextInt();
for(int tt=1;tt<=ttt;tt++){
int n = sc.nextInt();
String s = sc.next();
String s1="abcdefghijklmnopqrstuvwxyz";
String t = "";
for(int i=s.length()-1;i>=0;i--){
if(s.charAt(i)!='0'){
int k = (s.charAt(i)-'0');
// System.out.println(k);
t=(s1.charAt(k-1)+t);
}
else{
int k = Integer.parseInt(s.substring(i-2,i));
t=(s1.charAt(k-1)+t);
i-=2;
}
}
System.out.println(t);
}
}
public static int binarySearch(int arr[],int ele) {
int l = 0, r = arr.length-1;
int result1 = 0;
while (l <= r) {
int mid = l + (r - l) / 2;
if (arr[mid] >=ele) {
l = mid + 1;
result1 = mid;
} else {
r = mid - 1;
}
}
return result1;
}
private static long sqrt(long num) {
long l = 0;
long h = Integer.MAX_VALUE;
long mid;
while (h - l > 1) {
mid = (h + l)/2;
if (mid*mid <= num) {
l = mid;
}else {
h = mid;
}
}
return l;
}
public static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static class Pair {
public long x;
public long y;
public Pair(long x, long y) {
this.x = x;
this.y = y;
}
}
public static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | deaee37e80d2b00388889e484c1ceaba | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int q = Integer.parseInt(s.nextLine());
for (int t = 0; t < q; ++t) {
int n = Integer.parseInt(s.nextLine());
String str = s.nextLine();
String ret = "";
int i = 0;
while (i < str.length()) {
if (i < str.length() - 3 && str.charAt(i + 2) == '0' && str.charAt(i + 3) == '0') {
ret += "" + (char)(Integer.parseInt(str.substring(i, i + 1)) + 97 - 1);
i += 1;
} else if (i < str.length() - 2 && str.charAt(i + 2) == '0') {
// int x = Integer.parseInt(str)
// System.out.println((Integer.parseInt(str.substring(i, i + 2))));
ret += "" + (char)(Integer.parseInt(str.substring(i, i + 2)) + 97 - 1);
i += 3;
} else {
// System.out.println(Integer.parseInt(str.substring(i, i + 1)));
ret += "" + (char)(Integer.parseInt(str.substring(i, i + 1)) + 97 - 1);
i += 1;
}
}
System.out.println(ret);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1d81ea4292f4dafa3692e23e50b9830c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int z = 0; z < t; z++) {
int n = in.nextInt();
char[] chars = in.next().toCharArray();
String ans = "";
for(int i = n - 1; i >= 0; i--){
if (chars[i] == '0') {
int number = (chars[i - 1] - '0') + (chars[i - 2] - '0') * 10;
ans = (char)(number - 1 + 'a') + ans;
i -= 2;
}
else{
ans = (char)(chars[i] - '1' + 'a') + ans;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | f6e2ffbe6d7229c04988884ac6a73ef0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args)
{
Scanner t = new Scanner(System.in);
int w = t.nextInt();
while(w-->0)
{
int a = t.nextInt();
String s1 = t.next();
String s2 ="";
for(int i=s1.length()-1;i>=0;i--)
{
if(s1.charAt(i)!='0')
{
s2 = (char)(96+s1.charAt(i)-'0')+s2;
}
else{
i = i-2;
String temp = ""+s1.charAt(i)+s1.charAt(i+1);
s2 = (char)(96+Integer.parseInt(temp))+s2;
}
}
System.out.println(s2);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c80eb1ed77a9e0076b5abad19f9096d0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
public class Main {
static final long MOD1=1000000007;
static final long MOD=998244353;
static final int NTT_MOD1 = 998244353;
static final int NTT_MOD2 = 1053818881;
static final int NTT_MOD3 = 1004535809;
static long MAX = 1000000000000000000l;//10^18
static int index = 2;
public static void main(String[] args){
PrintWriter out = new PrintWriter(System.out);
InputReader sc=new InputReader(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
char[] cs = sc.next().toCharArray();
StringBuilder sb = new StringBuilder();
for (int j = n - 1; j >= 0; j--) {
if (cs[j] == '0') {
int z = 10 * Character.getNumericValue(cs[j - 2]) + Character.getNumericValue(cs[j - 1]);
sb.append((char)(z + (int)'a' - 1));
j-=2;
}else {
int z = Character.getNumericValue(cs[j]);
sb.append((char)(z + (int)'a' - 1));
}
}
out.println(sb.reverse());
}
out.flush();
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0403f3c57bf60e643d1468852ac2bdaa | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.PrintWriter;
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int tests = Integer.parseInt(sc.next());
for (int t = 0; t < tests; t++) {
int n = sc.nextInt();
String s = sc.next();
pw.println(getOriginalString(s));
}
sc.close();
pw.close();
}
static String getOriginalString(String s) {
if (s.length()==0) {
return "";
}
if (s.length() < 3) {
if (s.length() == 1) {
return String.valueOf((char)(s.charAt(0) - '1' + 'a'));
} else {
return String.valueOf((char)(s.charAt(0) - '1' + 'a')) + ((char)(s.charAt(1) - '1' + 'a'));
}
}
if (s.charAt(2) == '0' && (s.length()==3 || s.charAt(3)!='0')) {
return (char)(Integer.parseInt(s.substring(0, 2)) - 1 + 'a') + getOriginalString(s.substring(3));
} else {
return (char)(Integer.parseInt(s.substring(0, 1)) - 1 + 'a') + getOriginalString(s.substring(1));
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 8649903fdfeb00e420a646d18bdb506b | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for(int i = 0; i < t; i++) {
int length = scan.nextInt();
String s = scan.next();
String output = "";
for(int j = length - 1; j >= 0; j--) {
if(s.charAt(j) != '0') {
output = (char)((96 + s.charAt(j)) - '0') + output;
}
else {
j = j - 2;
String temp = "" + s.charAt(j) + s.charAt(j + 1);
output = (char)(96 + Integer.valueOf(temp)) + output;
}
}
System.out.println(output);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | dd3694ebe3428ce31fb40fb226263575 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for(int i = 0; i < t; i++) {
int length = scan.nextInt();
String s = scan.next();
String output = "";
for(int j = length - 1; j >= 0; j--) {
if(s.charAt(j) != '0') {
output = (char)((96 + s.charAt(j)) - '0') + output;
}
else {
j = j - 2;
String temp = "" + (char)(s.charAt(j)) + (char)(s.charAt(j + 1));
output = (char)(96 + Integer.valueOf(temp)) + output;
}
}
System.out.println(output);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 51c35d97e38f4ed40ab26bf3835a716e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for(int i = 0; i < t; i++) {
int length = scan.nextInt();
String str = scan.next();
String output = "";
for(int j = length - 1; j >= 0; j--) {
if(str.charAt(j) != '0') {
output = (char)((96 + str.charAt(j)) - '0') + output;
}
else {
j = j - 2;
String temp = "" + (char)str.charAt(j) + (char)str.charAt(j + 1);
output = (char)(96 + Integer.valueOf(temp)) + output;
}
}
System.out.println(output);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 201df26ac1de9fa1075557f06217e8ed | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void Draw(int n,int y){
if(n==y){
return;
}
for(int i=0;i<=y;i++){
System.out.print("#");
}
System.out.println();
Draw(n,y+1);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int tt=0;tt<t;tt++){
int n=sc.nextInt();
String s=sc.next();
StringBuilder sb=new StringBuilder();
char c='0';
String q="abcdefghijklmnopqrstuvwxyz";
int ans=0;
for(int i=n-1;i>=0;i--){
if(s.charAt(i)=='0'){
ans=Integer.parseInt(s.substring(i-2,i));
sb.append(q.charAt(ans-1));
i-=2;
}
else{
sb.append(q.charAt((s.charAt(i)-'0')-1));
}
}
sb.reverse();
System.out.println(sb);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 3f75beb75163cdac2f3681298d9866b0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
int t;
char c = 0;
String st, s2 = "";
String[] re = new String[T];
for (int i = 0; i < T; i++) {
s2 = "";
t = in.nextInt();
st = in.next();
for (int k = 0; k < st.length();) {
if (st.length() - k >= 4 && st.charAt(k + 2) == '0' && st.charAt(k + 3) == '0') {
c = (char) (49 + (st.charAt(k) - 1));
s2 += c;
c = (char) ((st.charAt(k + 1) - 48) * 10 + st.charAt(k + 2) + 48);
s2 += c;
k += 4;
} else {
if (st.length() - k >= 3 && st.charAt(k + 2) == '0') {
c = (char) ((st.charAt(k) - 48) * 10 + st.charAt(k+1) + 48);
s2 += c;
k += 3;
} else {
c = (char) (49 + (st.charAt(k) - 1));
s2 += c;
k++;
}
}
}
re[i] = s2;
}
for (int m = 0; m < T; m++) {
System.out.println(re[m]);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1846170af6a40db9ced7171c9aa078a6 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
while (t-- > 0){
int n = Integer.parseInt(sc.nextLine());
String st = sc.nextLine();
solve(st, n);
}
}
public static void solve(String num, int n){
char ch[] = num.toCharArray();
StringBuilder sb = new StringBuilder();
for(int i=n-1; i>=0; i--){
if (ch[i] == '0'){
int x = Integer.parseInt(String.valueOf(ch[i-1]));
int y = Integer.parseInt(String.valueOf(ch[i-2]));
y = y * 10 + x;
char c = (char)(y+96);
sb.append(c);
i-=2;
} else {
int x = Integer.parseInt(String.valueOf(ch[i]));
char c = (char)(x+96);
sb.append(c);
}
}
System.out.println(sb.reverse());
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 11 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0c2678717c1a8e2fb672c18381ca4708 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.LinkedList;
public class Main {
static InputReader in;
//static OutputWriter out;
static PrintWriter out;
public static void main(String[] args) throws Exception {
in=new InputReader(System.in);
//out=new OutputWriter(System.out);
out=new PrintWriter(new OutputStreamWriter(System.out));
int T=in.nextInt();
while(T-->0) {
int len=in.nextInt();
char[] str=(" "+in.next()).toCharArray();
LinkedList<Character> ans=new LinkedList<>();
for(int i=len;i>0;i--) {
if(str[i]=='0') {
i--;
int t=str[i]-'0';
i--;
t+=(str[i]-'0')*10;
ans.addFirst((char)(t+'a'-1));
}
else
ans.addFirst((char)(str[i]-'0'+'a'-1));
}
for(char c:ans)
out.print(c);
out.println();
}
out.flush();
}
static class InputReader {
private final BufferedReader br;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
int x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public long nextLong() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
long x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public String next() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
StringBuilder sb = new StringBuilder();
while (c > 32) {
sb.append((char) c);
c = br.read();
}
return sb.toString();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
static class OutputWriter {
private final BufferedWriter writer;
public OutputWriter(OutputStream out) {
writer=new BufferedWriter(new OutputStreamWriter(out));
}
public void print(String str) {
try {
writer.write(str);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void print(Object obj) {
print(String.valueOf(obj));
}
public void println(String str) {
print(str+"\n");
}
public void println() {
print('\n');
}
public void println(Object obj) {
println(String.valueOf(obj));
}
public void flush() {
try {
writer.flush();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ef5c0237b4d0ae651294e00244891644 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.LinkedList;
public class Main {
static InputReader in;
static OutputWriter out;
public static void main(String[] args) throws Exception {
in=new InputReader(System.in);
out=new OutputWriter(System.out);
int T=in.nextInt();
while(T-->0) {
int len=in.nextInt();
char[] str=(" "+in.next()).toCharArray();
LinkedList<Character> ans=new LinkedList<>();
for(int i=len;i>0;i--) {
if(str[i]=='0') {
i--;
int t=str[i]-'0';
i--;
t+=(str[i]-'0')*10;
ans.addFirst((char)(t+'a'-1));
}
else
ans.addFirst((char)(str[i]-'0'+'a'-1));
}
for(char c:ans)
out.print(c);
out.println();
}
out.flush();
}
static class InputReader {
private final BufferedReader br;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
int x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public long nextLong() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
long x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public String next() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
StringBuilder sb = new StringBuilder();
while (c > 32) {
sb.append((char) c);
c = br.read();
}
return sb.toString();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
static class OutputWriter {
private final BufferedWriter writer;
public OutputWriter(OutputStream out) {
writer=new BufferedWriter(new OutputStreamWriter(out));
}
public void print(String str) {
try {
writer.write(str);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void print(Object obj) {
print(String.valueOf(obj));
}
public void println(String str) {
print(str+"\n");
}
public void println() {
print('\n');
}
public void println(Object obj) {
println(String.valueOf(obj));
}
public void flush() {
try {
writer.flush();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0bda423f41b7d493a72eff4582e62aff | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.LinkedList;
public class Main {
static InputReader sc;
public static void main(String[] args) throws Exception {
os os=new os(System.out);
sc=new InputReader(System.in);
int T=sc.nextInt();
while(T-->0) {
int len=sc.nextInt();
char[] str=(" "+sc.next()).toCharArray();
LinkedList<Character> ans=new LinkedList<>();
for(int i=len;i>0;i--) {
if(str[i]=='0') {
i--;
int t=str[i]-'0';
i--;
t+=(str[i]-'0')*10;
ans.addFirst((char)(t+'a'-1));
}
else
ans.addFirst((char)(str[i]-'0'+'a'-1));
}
for(char c:ans)
os.write(c);
os.newLine();
}
os.flush();
}
static class InputReader {
BufferedReader br;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
int x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public long nextLong() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
long x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public String next() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
StringBuilder sb = new StringBuilder();
while (c > 32) {
sb.append((char) c);
c = br.read();
}
return sb.toString();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
static class os extends PrintStream {
private final BufferedWriter writer;
public os(OutputStream out) {
super(out);
writer=new BufferedWriter(new OutputStreamWriter(out));
}
public void write(int b) {
try {
out.write(b);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void write(byte buf[], int off, int len) {
try {
out.write(buf, off, len);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void write(char buf[]) {
try {
writer.write(buf);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void write(String s) {
try {
writer.write(s);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void newLine() {
try {
out.write('\n');
}
catch (IOException e) {
e.printStackTrace();
}
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0e9770febc899115dddcddbd11e61818 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class acmp {
public static void main(String[] args) {
FastScanner input = new FastScanner();
Algorithm algorithm = new Algorithm();
int t = input.nextInt();
while (t-- > 0) {
StringBuilder an = new StringBuilder();
int n = input.nextInt();
String s = input.nextToken();
String ans = "";
for (int i = n-1; i >= 0; i--) {
if(s.charAt(i) == '0'){
int g = Integer.parseInt(s.charAt(i-2) + "" + s.charAt(i-1)+"")-1;
i = i-2;
char c = (char) ('a' + g);
ans += c + "";
}else{
int f = Integer.parseInt(s.charAt(i)+ "")-1;
char c = (char) ('a' + f);
ans += c + "";
}
}
for (int i = ans.length()-1; i >= 0; i--) {
an.append(ans.charAt(i));
}
System.out.println(an);
}
}
}
class Algorithm {
int maxElement(int[] a) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < a.length; ++i) {
max = Math.max(max, a[i]);
}
return max;
}
int lower_bound(int[] a, int x) {
int l = 1, r = a.length, ans = 0;
while ((r - l) >= 0) {
int m = (l + r) >> 1;
if (a[m] >= x) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
return ans;
}
int upper_bound(int[] a, long x) {
int l = 1, r = a.length;
while ((r - l) >= 0) {
int m = l + r >> 1;
if (a[m] > x) {
r = m - 1;
} else {
l = m + 1;
}
}
return l;
}
boolean sqrt(long x){
long l = 0;
long r = 10000000L;
while((r - l) >= 0){
long m = (l + r) >> 1;
long square = (long) m * m;
if(square == x) return true;
if (square > x) r = m - 1;
else l = m + 1;
}
return false;
}
boolean isPrime(long n){
if (n < 2) return false;
if (n == 2 || n == 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
long end = (long) Math.sqrt(n) + 1;
for (long i = 6; i <= end; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0) return false;
}
return true;
}
long[] prefixSum(int[] arr) {
long[] prefixsum = new long[arr.length];
for (int i = 1; i < arr.length; i++) {
prefixsum[i] = prefixsum[i-1] + arr[i];
}
return prefixsum;
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(){
init();
}
public FastScanner(String name) {
init(name);
}
public FastScanner(boolean isOnlineJudge){
if(!isOnlineJudge || System.getProperty("ONLINE_JUDGE") != null){
init();
}else{
init("input.txt");
}
}
private void init(){
br = new BufferedReader(new InputStreamReader(System.in));
}
private void init(String name){
try {
br = new BufferedReader(new FileReader(name));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public String nextToken(){
while(st == null || !st.hasMoreElements()){
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt(){
return Integer.parseInt(nextToken());
}
public long nextLong(){
return Long.parseLong(nextToken());
}
public double nextDouble(){
return Double.parseDouble(nextToken());
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a3f501e29e318b4de5b9ab870fa2678d | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import javax.crypto.spec.PSource;
import java.math.MathContext;
import java.util.*;
public class exercie {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String s = sc.next();
String ans = "";
for(int i = n-1; i >= 0; i--){
if(s.charAt(i) == '0'){
ans = (char)(Integer.parseInt("" + s.charAt(i-2) + s.charAt(i-1)) + 96) + ans;
i-=2;
}else{
ans = (char)(s.charAt(i) + 48) + ans;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 5e7f050c0c83d2a9635950419dc19ca3 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int tc=sc.nextInt();
for(int i=0; i<tc; i++) {
int length=sc.nextInt();
String s=sc.next();
String ans="";
for(int j=length-1; j>=0; j--) {
if(s.charAt(j)!='0') {
ans=(char)((48+s.charAt(j)))+ans;
}
else {
j=j-2;
String temp=""+(char)s.charAt(j)+(char)s.charAt(j+1);
ans=(char)(96+Integer.parseInt(temp))+ans;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 4715dad285a0d058f47d169fdb5a111c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int tc=sc.nextInt();
for(int i=0; i<tc; i++) {
int length=sc.nextInt();
String s=sc.next();
String ans="";
for(int j=length-1; j>=0; j--) {
if(s.charAt(j)!='0') {
ans=(char)((96+s.charAt(j))-'0')+ans;
}
else {
j=j-2;
String temp=""+(char)s.charAt(j)+(char)s.charAt(j+1);
ans=(char)(96+Integer.parseInt(temp))+ans;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 8fb52502b61d04922a5acd1421df8a99 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public final class DecodeString {
private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
private DecodeString() {
}
public static void main(String[] args) throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
int numberOfTests = Integer.parseInt(reader.readLine());
String[] decodedStrings = new String[numberOfTests];
for (int i = 0; i < numberOfTests; i++) {
int lengthOfCodedString = Integer.parseInt(reader.readLine());
String codedString = reader.readLine();
decodedStrings[i] = decode(lengthOfCodedString, codedString);
}
for (String decodedString : decodedStrings) {
System.out.println(decodedString);
}
}
}
private static String decode(int n, String t) {
StringBuilder decodedStringBuilder = new StringBuilder();
int i = 0;
while (i < n) {
if (isZeroAt(t, i + 2) && !isZeroAt(t, i + 3) ) {
decodedStringBuilder.append(ALPHABET.charAt(Integer.parseInt(t.substring(i, i + 2)) - 1));
i += 3;
} else {
decodedStringBuilder.append(ALPHABET.charAt(Integer.parseInt(String.valueOf(t.charAt(i))) - 1));
i++;
}
}
return decodedStringBuilder.toString();
}
private static boolean isZeroAt(String t, int index) {
try {
return t.charAt(index) == '0';
} catch (IndexOutOfBoundsException e) {
return false;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a530932c21a05a1343ba79fa784a2048 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
public class exer {
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
FastScanner f = new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int e = f.nextInt();
for (int i = 0; i < e; i++) {
int x = f.nextInt();
String str = "abcdefghijklmnopqrstuvwxyz";
char[] ch = str.toCharArray();
String str1 = f.next();
char[] ch1 = str1.toCharArray();
String ans = "";
for (int j = ch1.length-1; j >= 0; j--) {
if(ch1[j]=='0'){
j--;
if(ch1[j]=='0'){
j--;
ans = ans + ch[Integer.parseInt(ch1[j]+"0")-1];
}
else{
ans = ans + ch[Integer.parseInt(ch1[j-1]+""+ch1[j])-1];
j--;
}
}
else{
ans = ans + ch[Integer.parseInt(ch1[j]+"")-1];
}
}
StringBuilder input1 = new StringBuilder();
// append a string into StringBuilder input1
input1.append(ans);
// reverse StringBuilder input1
input1.reverse();
System.out.println(input1);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0b23eccea7188f1cbfc0b135bf348977 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() {return Double.parseDouble(next());}
String nextLine() {
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader f = new FastReader();
int e = f.nextInt();
for (int i = 0; i < e; i++) {
int x = f.nextInt();
String str = "abcdefghijklmnopqrstuvwxyz";
char[] ch = str.toCharArray();
String str1 = f.next();
char[] ch1 = str1.toCharArray();
String ans = "";
for (int j = ch1.length-1; j >= 0; j--) {
if(ch1[j]=='0'){
j--;
if(ch1[j]=='0'){
j--;
ans = ans + ch[Integer.parseInt(ch1[j]+"0")-1];
}
else{
ans = ans + ch[Integer.parseInt(ch1[j-1]+""+ch1[j])-1];
j--;
}
}
else{
ans = ans + ch[Integer.parseInt(ch1[j]+"")-1];
}
}
StringBuilder input1 = new StringBuilder();
// append a string into StringBuilder input1
input1.append(ans);
// reverse StringBuilder input1
input1.reverse();
System.out.println(input1);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | fef34a20e52c5b834d72f25aec583eee | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.StringTokenizer;
public class cf_b {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder output = new StringBuilder();
public static void main(String[] args) throws NumberFormatException, IOException {
int T = Integer.parseInt(reader.readLine());
for (int t = 1; t <= T; t++) {
int N = Integer.parseInt(reader.readLine());
String incoding = reader.readLine();
for (int n = 0, zp = n + 2; n < N; n++, zp = n + 2) {
if (zp + 1 < N && incoding.charAt(zp) == '0' && incoding.charAt(zp + 1) == '0') {
char c = (char) ((incoding.charAt(n++) - '1') + 'a');
output.append(c);
int nbr = (incoding.charAt(n++) - '0') * 10 + (incoding.charAt(n++) - '1');
char c2 = (char) (nbr + 'a');
output.append(c2);
}else if (zp < N && incoding.charAt(zp) == '0') {
int nbr = (incoding.charAt(n++) - '0') * 10 + (incoding.charAt(n++) - '1');
char c = (char) (nbr + 'a');
output.append(c);
}else {
char c = (char) ((incoding.charAt(n) - '1') + 'a');
output.append(c);
}
}
output.append("\n");
}
System.out.print(output);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e8d1a61cd47af6e1ecf820d34a188db8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testes = sc.nextInt();
sc.nextLine();
for(int i = 0; i<testes; i++) {
sc.nextLine();
String s = sc.nextLine();
System.out.print(result2(s));
System.out.println("");
}
sc.close();
}
static String result2(String s) {
int size = 0;
for(int j = s.length() - 1; j>=0; j--) {
if(s.charAt(j) == '0') j = j-2;
size++;
}
char[] arr = new char[size];
for(int j = s.length() - 1; j>=0; j--) {
if(s.charAt(j) == '0') {
StringBuilder v = new StringBuilder();
v.append(s.charAt(j-2));
v.append(s.charAt(j-1));
int t = (Integer.parseInt(v.toString())-1)%26;
char y = (char) ('a'+ t);
arr[size-1] = y;
j = j-2;
}
else {
StringBuilder v = new StringBuilder();
v.append(s.charAt(j));
int t = (Integer.parseInt(v.toString())-1)%26;
char y = (char) ('a'+ t);
arr[size-1] = y;
}
size--;
}
return new String(arr);
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 3fb74e1779f11411cc7dac5c9f8a0062 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Main obj= new Main();
Scanner sc=new Scanner(System.in);
int t , n;
String s="";
t=sc.nextInt();
for(int j=0;j<t;j++){
n=sc.nextInt();
sc.nextLine();
s=sc.nextLine();
String st="";
char o=' ';
for(int i=n-1;i>=0;){
if(s.charAt(i)=='0'){
o=obj.ch(Integer.parseInt(s.substring(i-2,i)));
i-=3;
}
else
{
o=obj.ch(Character.getNumericValue(s.charAt(i)));
i--;
}
st=st+o;
}
System.out.println(""+obj.reverse(st));
}
}
char ch(int n){
char s=' ';
int c=0;
for(int i=97;i<=122;i++){
c++;
if(c==n)
s=(char)i;
}
return s;
}
String reverse(String n){
String g="";
for(int i=0;i<n.length();i++){
char ch=n.charAt(i);
g=ch+g;
}
return g;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1dd6b1d2e4fa42b935d10c4c24a41814 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class DecodeString1{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
while(q>0){
q--;
int n = sc.nextInt();
String t = sc.next();
String s = "";
for(int i=n-1; i>=0; i--){
if(t.charAt(i)=='0'){
s = Character.toString((char) (Integer.parseInt(t.substring(i-2, i))+96) ) + s;
i -= 2;
} else{
s = Character.toString((char)(t.charAt(i)+48) ) + s;
}
}
System.out.println(s);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | f4ce582a72983aab368eb917b989ba79 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class DecodeString1{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
while(q>0){
q--;
int n = sc.nextInt();
String t = sc.next();
String s = "";
for(int i=n-1; i>=0; i--){
if(t.substring(i,i+1).compareTo("0")==0){
s = Character.toString((char) (Integer.parseInt(t.substring(i-2, i))+96) ) + s;
i -= 2;
} else{
s = Character.toString((char) (Integer.parseInt(t.substring(i, i+1))+96) ) + s;
}
}
System.out.println(s);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | efd0f4633fb8bd524b5dade1f8d45bac | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
public class pp {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
char[] temp = new char[27];
for(int i = 1; i < 27; i++)
{
temp[i] = (char) ('a' + (i - 1));
}
PrintWriter pw = new PrintWriter(System.out);
while (testCases -- > 0)
{
int length = sc.nextInt();
LinkedList<Character> res = new LinkedList<>();
String s = sc.next();
for(int i = length - 1; i >= 0; i--)
{
if(s.charAt(i) != '0')
{
String h = "" + s.charAt(i);
int y = Integer.parseInt(h);
res.addFirst(temp[y]);
}
else
{
char prev = s.charAt(i - 1);
char secondPrev = s.charAt(i - 2);
i--;
i--;
String x = secondPrev + "" + prev;
int n = Integer.parseInt(x);
res.addFirst(temp[n]);
}
}
for(char x : res)
pw.print(x);
pw.println();
}
pw.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 912ccb7c9631d29db2c5032699acac1c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
public class B {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
String ans = "";
while(t-- > 0){
int n = sc.nextInt();
String s = sc.nextLine();
int a = 0;
outer:
while(a < n){
int first = s.charAt(a) - '0' - 1;
if(first == -1 ){
a+=1;
continue outer;
}
if(a + 2 < s.length() && first < 3){
if( s.charAt(a+2) > '6'){
ans+=((char)('a'+first));
a+=1;
continue outer;
}
if(s.charAt(a+2) == '0' ){
if(a + 3 < s.length()){
if(s.charAt(a+3) == '0'){
ans+=((char)('a'+first));
a+=1;
continue outer;
}else{
int in = Integer.parseInt(s.substring(a,a+2)) - 1;
ans+=((char)('a' + in));
a+=3;
continue outer;
}
}else{
int in = Integer.parseInt(s.substring(a,a+2)) - 1;
ans+=((char)('a' + in));
a+=3;
continue outer;
}
}else{
ans+=((char)('a'+first));
a+=1;
continue outer;
}
}else {
ans+=((char)('a'+first));
a+=1;
continue outer;
}
}
out.println(ans);
ans ="";
}
}
private static void no() {
out.println("No");
}
private static void yes() {
out.println("Yes");
}
public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception
{
int[] arr = new int[N];
st = new StringTokenizer(infile.readLine());
for(int i=0; i < N; i++)
arr[i] = Integer.parseInt(st.nextToken());
return arr;
}
//input shenanigans
/*
Random stuff to try when stuck:
-if it's 2C then it's dp
-for combo/probability problems, expand the given form we're interested in
-make everything the same then build an answer (constructive, make everything 0 then do something)
-something appears in parts of 2 --> model as graph
-assume a greedy then try to show why it works
-find way to simplify into one variable if multiple exist
-treat it like fmc (note any passing thoughts/algo that could be used so you can revisit them)
-find lower and upper bounds on answer
-figure out what ur trying to find and isolate it
-see what observations you have and come up with more continuations
-work backwards (in constructive, go from the goal to the start)
-turn into prefix/suffix sum argument (often works if problem revolves around adjacent array elements)
-instead of solving for answer, try solving for complement (ex, find n-(min) instead of max)
-draw something
-simulate a process
-dont implement something unless if ur fairly confident its correct
-after 3 bad submissions move on to next problem if applicable
-do something instead of nothing and stay organized
-write stuff down
Random stuff to check when wa:
-if code is way too long/cancer then reassess
-switched N/M
-int overflow
-switched variables
-wrong MOD
-hardcoded edge case incorrectly
Random stuff to check when tle:
-continue instead of break
-condition in for/while loop bad
Random stuff to check when rte:
-switched N/M
-long to int/int overflow
-division by 0
-edge case for empty list/data structure/N=1
*/
public static long[] readArr2(int N, BufferedReader infile, StringTokenizer st) throws Exception
{
long[] arr = new long[N];
st = new StringTokenizer(infile.readLine());
for(int i=0; i < N; i++)
arr[i] = Long.parseLong(st.nextToken());
return arr;
}
public static boolean isPrime(long n)
{
if(n < 2) return false;
if(n == 2 || n == 3) return true;
if(n%2 == 0 || n%3 == 0) return false;
long sqrtN = (long)Math.sqrt(n)+1;
for(long i = 6L; i <= sqrtN; i += 6) {
if(n%(i-1) == 0 || n%(i+1) == 0) return false;
}
return true;
}
public static long gcd(long a, long b)
{
if(a > b)
a = (a+b)-(b=a);
if(a == 0L)
return b;
return gcd(b%a, a);
}
public static long totient(long n)
{
long result = n;
for (int p = 2; p*p <= n; ++p)
if (n % p == 0)
{
while(n%p == 0)
n /= p;
result -= result/p;
}
if (n > 1)
result -= result/n;
return result;
/*
find phi(i) from 1 to N fast
O(N*loglogN)
long[] arr = new long[N+1];
for(int i=1; i <= N; i++)
arr[i] = i;
for(int v=2; v <= N; v++)
if(arr[v] == v)
for(int a=v; a <= N; a+=v)
arr[a] -= arr[a]/v;
*/
}
public static ArrayList<Integer> findDiv(int N)
{
//gens all divisors of N
ArrayList<Integer> ls1 = new ArrayList<Integer>();
ArrayList<Integer> ls2 = new ArrayList<Integer>();
for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++)
if(N%i == 0)
{
ls1.add(i);
ls2.add(N/i);
}
Collections.reverse(ls2);
for(int b: ls2)
if(b != ls1.get(ls1.size()-1))
ls1.add(b);
return ls1;
}
public static void sort(int[] arr)
{
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Integer> ls = new ArrayList<Integer>();
for(int x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
public static long power(long x, long y, long p)
{
//0^0 = 1
long res = 1L;
x = x%p;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%p;
y >>= 1;
x = (x*x)%p;
}
return res;
}
//custom multiset (replace with HashMap if needed)
public static void push(TreeMap<Integer, Integer> map, int k, int v)
{
//map[k] += v;
if(!map.containsKey(k))
map.put(k, v);
else
map.put(k, map.get(k)+v);
}
public static void pull(TreeMap<Integer, Integer> map, int k, int v)
{
//assumes map[k] >= v
//map[k] -= v
int lol = map.get(k);
if(lol == v)
map.remove(k);
else
map.put(k, lol-v);
}
public static int[] compress(int[] arr)
{
ArrayList<Integer> ls = new ArrayList<Integer>();
for(int x: arr)
ls.add(x);
Collections.sort(ls);
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int boof = 1; //min value
for(int x: ls)
if(!map.containsKey(x))
map.put(x, boof++);
int[] brr = new int[arr.length];
for(int i=0; i < arr.length; i++)
brr[i] = map.get(arr[i]);
return brr;
}
public static long[][] multiply(long[][] left, long[][] right)
{
long MOD = 1000000007L;
int N = left.length;
int M = right[0].length;
long[][] res = new long[N][M];
for(int a=0; a < N; a++)
for(int b=0; b < M; b++)
for(int c=0; c < left[0].length; c++)
{
res[a][b] += (left[a][c]*right[c][b])%MOD;
if(res[a][b] >= MOD)
res[a][b] -= MOD;
}
return res;
}
public static long[][] power(long[][] grid, long pow)
{
long[][] res = new long[grid.length][grid[0].length];
for(int i=0; i < res.length; i++)
res[i][i] = 1L;
long[][] curr = grid.clone();
while(pow > 0)
{
if((pow&1L) == 1L)
res = multiply(curr, res);
pow >>= 1;
curr = multiply(curr, curr);
}
return res;
}
}
class FastScanner
{
//I don't understand how this works lmao
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] nextInts(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] nextLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC) c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = getChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 3598e9ebb64f291c76dba252dd6be3df | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class strung
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double q = in.nextInt();
for(int z = 0; z < q; z++) {
double n = in.nextInt();
String str = in.next();
String d = new StringBuilder(str).reverse().toString();
String otvet = "";
for (int i = 0; i < n; i++) {
String sub = d.substring(i, i+1);
String o = "0";
if (sub.equals(o)){
String bykva = new StringBuilder(d.substring(i+1, i+3)).reverse().toString();
int fo = Integer.parseInt(bykva)+96;
otvet = otvet + (char)fo;
i = i+2;
} else {
int foo = Integer.parseInt(sub)+96;
otvet = otvet + (char)foo;
}
}
String otv = new StringBuilder(otvet).reverse().toString();
System.out.println(otv);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 49f8e7b58454a3f0528894aa9ae8bb5c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class strung
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double q = in.nextInt();
for(int z = 0; z < q; z++) {
double n = in.nextInt();
String str = in.next();
String d = new StringBuilder(str).reverse().toString();
String otvet = "";
for (int i = 0; i < n; i++) {
String sub = d.substring(i, i+1);
String o = "0";
if (sub.equals(o)){
String bykva = new StringBuilder(d.substring(i+1, i+3)).reverse().toString();
int fo = Integer.parseInt(bykva)+96;
otvet = otvet + (char)fo;
i = i+2;
} else {
int foo = Integer.parseInt(sub)+96;
otvet = otvet + (char)foo;
}
}
String otv = new StringBuilder(otvet).reverse().toString();
System.out.println(otv);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ee222b5ebb9941253793caf9b1056dee | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class solution{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
String s="";
int n=sc.nextInt();//6
String st=sc.next();//315045
sc.nextLine();
int num;
for(int i=n-1;i>=0;i--){
if(st.charAt(i)=='0'){
num=Integer.parseInt(st.substring(i-2,i));
i=i-2;
}
else
num=Integer.parseInt(st.substring(i,i+1));
s=(char)(96+num)+s;
}
System.out.println(s);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 19bcee69f7b2c71577963a77ead6b579 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class hello {
public static void main (String[] args) throws java.lang.Exception
{
Scanner s = new Scanner(System.in);
int t=s.nextInt();
for(int z=0;z<t;z++)
{
int n=s.nextInt();
String st = s.next();
String st1= "";
int arr[] = new int[n];
int b=0;
String st2="";
for(int i=n-1;i>=0;i--)
{
st1 = st1 + st.charAt(i);
}
for(int i=0;i<n;i++)
{
if(st1.charAt(i)=='0')
{
arr[b]=st1.charAt(i+1) - 48;
arr[b] = arr[b] + 10*(st1.charAt(i+2) - 48);
i=i+2;
b++;
}
else{
arr[b]=st1.charAt(i) - 48;
b++;
}
}
for(int i=b-1;i>=0;i--)
{
st2 = st2 + (char)(arr[i]+96);
}
System.out.println(st2);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a77b3ba8add62e9c4ba4489fbf9f8756 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class A {
public static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void print(int[] a) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.println();
}
public static String concat(String s1, String s2) {
return new StringBuilder(s1).append(s2).toString();
}
static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
static boolean isPrime(int n) {
if (n <= 1)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0)
return false;
}
return true;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t1 = sc.nextInt();
outer: while (t1-- > 0) {
int n = sc.nextInt();
String s = sc.next();
String x = "";
for (int i =n-1;i>-1;i--) {
if (s.charAt(i) == '0') {
x = (char)(Integer.parseInt(s.substring(i-2,i))+96)+x;
i-=2;
}else {
x = (char)(Character.getNumericValue(s.charAt(i))+96)+""+x;
}
}
out.println(x);
/*
* 315045
*
*
*
*
*/
}
out.close();
}
static class Pair implements Comparable<Pair> {
long first;
long second;
public Pair(long first, long second) {
this.first = first;
this.second = second;
}
public int compareTo(Pair p) {
if (first != p.first)
return Long.compare(first, p.first);
else if (second != p.second)
return Long.compare(second, p.second);
else
return 0;
}
}
static class Tuple implements Comparable<Tuple> {
long first;
long second;
long third;
public Tuple(long a, long b, long c) {
first = a;
second = b;
third = c;
}
public int compareTo(Tuple t) {
if (first != t.first)
return Long.compare(first, t.first);
else if (second != t.second)
return Long.compare(second, t.second);
else if (third != t.third)
return Long.compare(third, t.third);
else
return 0;
}
}
static final Random random = new Random();
static void shuffleSort(int[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
int r = random.nextInt(n), temp = a[r];
a[r] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
long[] readArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | fe5ebeac0ccc38523a1d2d47f04ad3c3 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t>0)
{
int n=s.nextInt();
String str=s.next();
String ans="";
char c[]=new char[n];
for(int i=n-1;i>=0;i--)
{
int l=str.charAt(i)-'0';
if(l==0)
{
int temp=10*(str.charAt(i-2)-'0')+str.charAt(i-1)-'0'+96;
char store=(char)temp;
ans=store+ans;
i=i-2;
}
else
{
int temp=str.charAt(i)-'0'+96;
char store =(char)temp;
ans =store+ans;
}
}
System.out.println(ans);
t--;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | de938350d394a5eb5211e7b3c2580d6c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // "static void main" must be defined in a public class.
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int T = fs.nextInt();
for(int i = 0; i < T; i++) {
int N = fs.nextInt();
String s = fs.next();
char[] ch = s.toCharArray();
String ans = "";
if(ch.length == 1) {
int first = Character.getNumericValue(ch[0]);
int digit = first + 96;
char c = (char)digit;
ans += c;
out.println(ans);
continue;
}
// if(ch.length == 2) {
// if(ch[0] != '0' && ch[1] != '0') {
// int first = Character.getNumericValue(ch[0]);
// int digit = first + 96;
// char c = (char)digit;
// int second = Character.getNumericValue(ch[1]);
// int digit1 = first + 96;
// char ca = (char)digit1;
// ans += c;
// ans += ca;
// }else{
// int first1 = Character.getNumericValue(ch[1]);
// int second1 = Character.getNumericValue(ch[0]);
// int digit1 = 96 + (10*second1 + first1);
// char c =(char)digit1;
// ans += c;
// }
// out.println(ans);
// continue;
// }
for(int j = 0; j < ch.length-1; j++) {
String str = "";
if(ch[j] != '0') {
int first = Character.getNumericValue(ch[j]);
int digit = first + 96;
char c = (char)digit;
str+= c;
ans += str;
}else{
if(ch[j+1] == '0') {
int first = Character.getNumericValue(ch[j]);
int second = Character.getNumericValue(ch[j-1]);
int digit = 96 + (10*second + first);
char c =(char)digit;
str += c;
String sub = ans.length() >= 2 ? ans.substring(0, ans.length()-1) : "";
ans = sub + str;
j++;
}else{
int first = Character.getNumericValue(ch[j-1]);
int second = Character.getNumericValue(ch[j-2]);
int digit = 96 + (10*second + first);
char c =(char)digit;
str += c;
String sub = ans.length() > 2 ? ans.substring(0, ans.length()-2) : "";
ans = sub + str;
}
}
}
if(ch[N-1] == '0' && ch[N-2] != '0') {
int first = Character.getNumericValue(ch[N-1-1]);
int second = Character.getNumericValue(ch[N-1-2]);
int digit = 96 + (10*second + first);
char c =(char)digit;
String sub = ans.length() > 2 ? ans.substring(0, ans.length()-2) : "";
ans = sub + c;
}else if(ch[N-1] == '0' && ch[N-2] == '0') {
}else if(ch[N-1] != 0) {
int first = Character.getNumericValue(ch[N-1]);
int digit = first + 96;
char c = (char)digit;
ans += c;
}
out.println(ans);
}
out.close();
}
static int gcd(int a, int b) {
if(b == 0) {
return a;
}else{
return gcd(b, a%b);
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | d220b502b3a95955ed6c59f540ca98f7 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class DecodingString {
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t!=0){
t--;
int n=Integer.parseInt(br.readLine());
String []codeNum=br.readLine().split("");
int []nums=new int[n];
int k=0;
for(String s:codeNum){
nums[k++]=Integer.parseInt(s);
}
StringBuilder code= new StringBuilder();
char ch;
int i,b=10;
for(i=n-1;i>1;i--){
if(nums[i]==0){
if(nums[i-1]==0){
if(nums[i-2]==2)b=20;
ch = (char) (b + 96);
code.insert(0, ch);
b=10;
}else {
ch = (char) (nums[i - 2] * 10 + nums[i - 1] + 96);
code.insert(0, ch);
}
i-=2;
}else{
ch= (char) (nums[i]+96);
code.insert(0, ch);
}
}
while(i>=0) {
ch = (char) (nums[i--] + 96);
code.insert(0, ch);
}
System.out.println(code);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b055cc2e1a3160d73f90747134750b98 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Solve solver = new Solve();
int T = 1;
T = in.nextInt();
for (int i = 1; i <= T; i++) solver.solve(i, in, out);
out.close();
}
static class Solve {
public int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static final long inf = 0x3f3f3f3f;
static final int N = (int) 2e5 + 7;
static final int mod = (int) 1e9 + 7;
static final int[] monthDay = new int[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public void solve(int testNumber, InputReader in, OutputWriter out) {
//ow.println("Case #"+testNumber+": ");
//write code here
//long startTime = System.currentTimeMillis();
int n = in.nextInt();
String s = in.next();
char[] ch = s.toCharArray();
String ans = "";
for (int i = n-1; i >= 0; i--) {
if(ch[i] == '0'){
int x = Integer.parseInt(s.substring(i - 2, i));
ans += (char)(x + 'a' - 1);
i-=2;
}else{
ans += (char)(ch[i] - '0' + 'a' - 1);
}
}
ans = new StringBuilder(ans).reverse().toString();
out.println(ans);
//long endTime = System.currentTimeMillis();int time=(int) (endTime - startTime);System.out.println("运行时间:" + time + "ms");
//here is end!
}
static void test(int[] nums, OutputWriter out) {
for (int num : nums) out.print(num + " ");
out.println();
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
writer.println();
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
long sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return nextString();
}
public interface SpaceCharFilter {
boolean isSpaceChar(int ch);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b24a7caee099764ea177b1503c4e0c30 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author mpi
*/
public class DecodeString {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int tests = Integer.parseInt(br.readLine());
for (int i = 0; i < tests; ++i) {
br.readLine();
decode(br.readLine());
}
}
}
public static void decode(String s) {
StringBuilder sb = new StringBuilder(s.length());
rec(s, 0, sb);
System.out.println(sb);
}
static boolean rec(String s, int i, StringBuilder sb) {
if (i == s.length()) {
return true;
}
int c = s.charAt(i) - '0';
if (c == 0) {
return false;
}
if (c > 2) {
sb.append((char)('a' + (c - 1)));
if (!rec(s, i + 1, sb)) {
sb.setLength(sb.length() - 1);
return false;
}
return true;
}
boolean found = false;
if (i < s.length() - 2 && s.charAt(i + 2) == '0') {
int d = s.charAt(i + 1) - '0';
sb.append((char)('a' + (10 * c + d - 1)));
found = rec(s, i + 3, sb);
if (!found) {
sb.setLength(sb.length() - 1);
} else {
return true;
}
}
sb.append((char)('a' + (c - 1)));
if (!rec(s, i + 1, sb)) {
sb.setLength(sb.length() - 1);
return false;
}
return true;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e7daf0cd91d07afcfc1d4458fcd693f4 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int j=0;j<t;j++){
sc.nextLine();
int n=sc.nextInt();
sc.nextLine();
String s=sc.next();
StringBuilder sb=new StringBuilder();
for(int i=0;i<n;){
int val=s.charAt(i)-'0';
if((i+2<n && s.charAt(i+2)!='0') || (i+3<n && s.charAt(i+3)=='0') || i>=n-2){
char ch=(char)('a'+(val-1));
sb.append(ch);
i=i+1;
}
else{
val=val*10+(s.charAt(i+1)-'0');
char ch=(char)('a'+(val-1));
sb.append(ch);
i=i+3;
}
}
System.out.println(sb.toString());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | da118e3ac7697884b0cb008740651cea | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static MyScanner s=new MyScanner();
static int[]parent;
public static int find(int a){
if(parent[a]!=a)parent[a]=find(parent[a]);
return parent[a];
}
public static void union(int a,int b){
int fa=find(a),fb=find(b);
if(fa==fb)return;
parent[fa]=fb;
}
public static void main(String[] args) {
int K = s.nextInt();
while (K > 0) {
K--;
int n=s.nextInt();
char[]str=s.next().toCharArray();
boolean[]isvi=new boolean[n];
char[]ans=new char[n];
for(int i=0;i<n;i++){
if(isvi[i])continue;
if(str[i]=='0'){
if(i+1<n&&str[i+1]=='0'){
isvi[i+1]=true;ans[i+1]=0;
isvi[i]=true;ans[i]=0;
isvi[i-1]=true;ans[i-1]=(char)('a'+(str[i-1]-'0')*10-1);
}
else {
isvi[i-1]=true;ans[i-1]=0;
isvi[i-2]=true;ans[i-2]=(char)('a'+(str[i-2]-'0')*10+(str[i-1]-'0')-1);
isvi[i]=true;ans[i]=0;
}
}
}
for(int i=0;i<n;i++){
if(isvi[i])continue;
ans[i]=(char)(str[i]-'1'+'a');
}
StringBuilder ret=new StringBuilder();
for(int i=0;i<n;i++){
if(ans[i]==0)continue;
ret.append(ans[i]);
}
System.out.println(ret);
}
}
}
//区间dp问题,看两端(求回文时看两端),(最后两端可以作为方向需要加状态)
//看内部,dp[i][j] 与dp[i][k],dp[k+1][j]看顺序还是逆序(一般是逆序)
//递推方程(最优子结构)
/*
5
541408759 636014462 664058243 906405360
65998050 668310524 281481076 678509965
385782861 696386847 946646054 818865505
122407847 270493687 793205264 951022207
645270183 2434797 859142651 887597062
* */
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e260e120462a7fe5fddb1b7a17c05ed2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //package test;
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while(test-- > 0) {
int n = sc.nextInt() - 1;
String s = sc.next();
String decodedString = "";
while(n >= 0) {
String c = s.charAt(n) + "";
if(c.equals("0")) {
c = s.charAt(n - 2) + "" + s.charAt(n - 1);
n -= 2;
}
int ascii = (Integer.parseInt(c) - 1) + 97;
char character = (char)ascii;
decodedString += character;
n--;
}
System.out.println(new StringBuilder(decodedString).reverse());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | be5b4e60969b82f6173b4ed43597c335 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class Check2 {
public static void main(String[] args) {
FastReader f = new FastReader();
int x = f.nextInt();
Map map = new HashMap<>();
char z = 'a';
for (int i = 1; i <= 25; i++) {
map.put(i, z);
z++;
}
map.put(26, 'z');
for (int i = 0; i < x; i++) {
int y = f.nextInt();
String s = f.next();
String s1 = "";
for (int j = y - 1; j >= 0; j--) {
if (s.charAt(j) == '0'){
s1 += map.get(Integer.parseInt(s.substring(j-2, j)));
j=j-2;
} else {
s1 += map.get(Character.getNumericValue(s.charAt(j)));
}
}
StringBuffer buffer = new StringBuffer(s1);
System.out.println(buffer.reverse());
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 9c53135dcd82a739517c656e5e5ccb0e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;public class Main { public static void main(String[] args) {Scanner in = new Scanner(System.in);char [] alpha = "abcdefghijklmnopqrstuvwxyz".toCharArray();int t = in.nextInt();while (t--!=0) {int n = in.nextInt();String s = in.next();StringBuilder b = new StringBuilder();for (int i = n - 1 ; i>=0 ; i--) {if(s.charAt(i) == '0') {b.insert(0,alpha[Integer.parseInt(s.charAt(i-2)+""+s.charAt(i-1))-1]);i-=2;} else b.insert(0,alpha[Integer.parseInt(s.charAt(i)+"")-1]);}System.out.println(b);}}} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b37290eb733aba40a9b7215875832d01 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class Prac {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-->0){
int n = sc.nextInt();
int[] arr = new int[n];
String s = sc.next();
for (int i = 0; i < n; i++)
arr[i] = Integer.parseInt(s.charAt(i)+"");
if(n<=2) {
for (int i = 0; i < n; i++)
pw.print((char)('a' + (arr[i]-1)));
pw.println();
}
else{
Stack<Character> st = new Stack<>();
for(int i=n-1;i>=0;){
if(arr[i]==0) {
st.push((char) ('a' + (Integer.parseInt(arr[i - 2] + "" + arr[i - 1]) - 1)));
i -= 3;
}
else{
st.push((char)('a'+(arr[i]-1)));
i--;
}
}
while(!st.isEmpty())
pw.print(st.pop());
pw.println();
}
}
pw.close();
}
static int gcd ( int a, int b){
return a == 0 ? b : gcd(b % a, a);
}
static int lcm ( int a, int b){
return a * b / gcd(a, b);
}
static class Pair implements Comparable<Pair> {
int x;
int y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair p) {
return x == p.x ? y - p.y : x - p.x;
}
public String toString(){return x + " " + y;}
}
static class Tuple implements Comparable<Tuple> {
int x;
int y;
char c;
Tuple(char c,int x,int y){
this.c=c;
this.x=x;
this.y=y;
}
public int compareTo(Tuple t) {
return x == t.x ? y - t.y : x - t.x;
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public long[] nextlongArr(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public Long[] nextLongArr(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public int[] nextIntArr(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public Integer[] nextIntegerArr(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 49cfbbecb30f707ff5d565d0a46f4a8f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.abs;
import static java.lang.Math.sqrt;
public class MainClass{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int san = in.nextInt();
String s = in.next();
char[] chars = s.toCharArray();
String alphabit = ",abcdefghijklmnopqrstuvwxyz";
String result = "";
ArrayList<Character> array = new ArrayList<>();
for (int j = 0; j < chars.length; j++) {
array.add(chars[j]);
}
array.add(',');
array.add('.');
array.add('s');
for (int j = 0; j < array.size() - 3;) {
if(array.get(j) == '0') j++;
else {
if((array.get(j + 2) != '0' && array.get(j + 3) != '0') || (array.get(j + 2) != '0' && array.get(j + 3) == '0')) {
result += alphabit.charAt(Integer.parseInt(String.valueOf(array.get(j))));
j++;
// for (int k = 0; k < j + 1; k++) {
// array.remove(k);
// }
}
else if(array.get(j + 2) == '0' && array.get(j + 3) == '0') {
result += alphabit.charAt(Integer.parseInt(String.valueOf(array.get(j))));
result += alphabit.charAt(Integer.parseInt(String.valueOf((array.get(j + 1))) + String.valueOf(array.get(j + 2))));
j += 4;
}
else if((array.get(j + 2) == '0' && array.get(j + 3) != '0')){
result += alphabit.charAt(Integer.parseInt(String.valueOf(array.get(j)) + String.valueOf(array.get(j + 1))));
j += 3;
// for (int k = 0; k < j + 1; k++) {
// array.remove(k);
// }
}
}
}
System.out.println(result);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 17f36280315a5f237a9d9f32748383f6 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class ques{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
int t= sc.nextInt();
for (int i=0;i<t;i++){
int n= sc.nextInt();
String s= sc.next();
String ans="";
int num;
String s1;
if (s.length()==1){
num= Integer.parseInt(s)+96;
char answer= (char)num;
ans+=answer;
}
else if(s.length()==2){
char c1= s.charAt(0);
s1= c1+"";
num= Integer.parseInt(s1)+96;
char answer= (char)num;
ans+=answer;
c1= s.charAt(1);
s1= c1+"";
num= Integer.parseInt(s1)+96;
answer= (char)num;
ans+=answer;
}
else {for (int j=0; j<s.length()-3; j++){
if (s.charAt(j+2)=='0' && s.charAt(j+3)!='0')
{
char c1= s.charAt(j);
char c2= s.charAt(j+1);
s1= c1+""+c2;
num= Integer.parseInt(s1)+96;
char answer= (char)num;
ans+=answer;
j+=2;
}
else {
char c1= s.charAt(j);
s1= c1+"";
num= Integer.parseInt(s1)+96;
char answer= (char)num;
ans+=answer;
}
}
int l=s.length();
if (s.charAt(l-1)=='0') {
char c1= s.charAt(l-3);
char c2= s.charAt(l-2);
s1= c1+""+c2;
num= Integer.parseInt(s1)+96;
char answer= (char)num;
ans+=answer;
}
else if (s.charAt(l-2)=='0'){
char c1= s.charAt(l-1);
s1= c1+"";
num= Integer.parseInt(s1)+96;
char answer= (char)num;
ans+=answer;
}
else {
int v=l-3;
if (s.charAt(l-3)=='0') v=l-2;
for (int m=v; m<l; m++){
char c1= s.charAt(m);
s1= c1+"";
num= Integer.parseInt(s1)+96;
char answer= (char)num;
ans+=answer;
}
}}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 44e18a32449052285fe6dbec09b135d5 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class esep
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-->0)
{
char[] arr = "abcdefghijklmnopqrstuvwxyz".toCharArray();
int a = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
StringBuilder res = new StringBuilder();
int i = a-1;
while(i>=0)
{
if(s.charAt(i)=='0' && s.charAt(i-1) !='0')
{
res.append(arr[Integer.parseInt((s.charAt(i-2))+""+(s.charAt(i-1)))-1]);
i -= 3;
}
else if(s.charAt(i)=='0' && s.charAt(i-1) =='0')
{
res.append(arr[Integer.parseInt((s.charAt(i-2))+""+(s.charAt(i-1)))-1]);
i -= 3;
}
else
{
res.append(arr[Integer.parseInt(String.valueOf(s.charAt(i)))-1]);
--i;
}
}
String r = res.reverse().toString();
System.out.println(r);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | be8accd8ffa355be06ef691115ec46cd | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class cf {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
for (int i = 0; i <a; i++) {
int b=sc.nextInt();
String c=sc.next();
String q="";
String e="";
for (int j = 0; j < b; j++) {
if(c.charAt(j)!='0'){
q+=c.charAt(j);
}
else{
if(j+1<=b-1 && c.charAt(j+1)=='0' ){
q+=c.charAt(j);
}
else{
String p=c.charAt(j-2)+""+c.charAt(j-1);
int t=Integer.parseInt(p);
for (int k = 0; k < q.length()-2; k++) {
String l=(q.charAt(k)+"");
int y=Integer.parseInt(l);
e+=(char)(y+96);
}
e+=(char)(t+96);
q="";
}
}
}
for (int j = 0; j < q.length(); j++) {
String l=(q.charAt(j)+"");
int y=Integer.parseInt(l);
e+=(char)(y+96);
}
System.out.println(e);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 59bd12ffdfed7173e8ce605788558e30 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class abhinandan6065_Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int quary = sc.nextInt();
while (quary-- > 0) {
int n = sc.nextInt();
String str = sc.next();
String ans = "";
for (int i = n - 1; i >= 0; i--) {
char val = str.charAt(i);
if (val == '0') {
ans = Character.toString((char) (Integer.parseInt(str.substring(i - 2, i)) + 96)) + ans;
i -= 2;
} else {
ans = Character.toString((char) (val + 48)) + ans;
}
}
sb.append(ans + "\n");
}
System.out.print(sb);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ca422fa5012208c820c4910c5ad3865b | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Test02 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int firstSum = sc.nextInt();
for (int i = 0; i < firstSum; i++) {
int secondSum = sc.nextInt();
sc.nextLine();
String number = sc.nextLine();
int j, count = 0, k = 0;
String str="";
for (j = secondSum - 1; j >= 0; j--) {
if (number.charAt(j) == '0') {
int b = (number.charAt(j - 2) - 48) * 10 + (number.charAt(j - 1) + 48);
str=(char) b+str;
count++;
j -= 2;
} else {
str=(char)(48 + number.charAt(j))+str;
}
}
System.out.println(str);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c4f8c62dc4a6ee8666bb6ecce0e3fbf3 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class MyClass {
static Scanner in = new Scanner(System.in);
static int testCases, n;
static char s[];
static long a, b, c, mod = 998244353L;
static void solve() {
long x = 1L, y = 0L, mid = 2L;
for(int i = 4; i <= (int)a; i += 2) {
mid = (mid * 2 * (i - 1)) / (i / 2);
x = (mid / 2L) + y;
y = mid - x - 1L;
}
System.out.println(x % mod + " " + y % mod + " 1");
}
static char ch[] = {'-', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z'};
static void B() {
int zero = 0;
for(char i : s) {
if((i - '0') == 0 ) {
++zero;
}
}
StringBuilder ans = new StringBuilder();
if(zero == 0) {
for(char i : s) {
ans.append(ch[i - '0']);
}
System.out.println(ans.toString());
return;
} else {
int i = n - 1;
while(i >= 0) {
if(s[i] != '0') {
ans.append(ch[s[i] - '0']);
--i;
} else {
String t = Integer.parseInt(((s[i - 2] - '0') + "") + ((s[i - 1] - '0') + "") ) + "";
ans.append(ch[Integer.parseInt(t)]);
i -= 3;
}
}
}
ans.reverse();
System.out.println(ans.toString());
}
public static void main(String args[]) {
testCases = in.nextInt();
for(int t = 0; t < testCases; ++t) {
n = in.nextInt();
s = in.next().toCharArray();
B();
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 9a3fd436826b50b7e4d692b3350736db | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Nervose.Wu
* @date 2022/10/3 12:27
*/
public final class S820B {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
// write here
for(int i=sc.nextInt();i>0;i--){
int cur=sc.nextInt()-1;
String code=sc.next();
StringBuilder target=new StringBuilder();
while (cur>=0){
if(code.charAt(cur)=='0'){
target.append((char)('a'+Integer.parseInt(code.substring(cur-2,cur))-1));
cur-=3;
}else {
target.append((char)('a'+Integer.parseInt(code.substring(cur,cur+1))-1));
cur-=1;
}
}
out.println(target.reverse().toString());
}
out.close();
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 7b82b225497f0b672ac965986aa19ff3 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t>0) {
String result = "";
int n = sc.nextInt();
String ii = sc.next();
for (int i=n-1; i>-1; i--) {
int x = 0;
if (ii.charAt(i)=='0') {
i--;
String p = ii.substring(i-1, i+1);
x = Integer.parseInt(p);
i--;
} else {
x = Integer.parseInt(ii.charAt(i)+"");
}
x--;
char rr = (char)('a' + x);
result = rr + result;
}
System.out.println(result);
t--;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 942a0d9c025bd417f2c3dccddbd43a3c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
/**
* Created by Franz Andel <[email protected]>
* on 13 September 2022.
*/
public class DecodeString {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCases = scanner.nextInt();
for (int i = 0; i < testCases; i++) {
int encodedStringLength = scanner.nextInt();
String encodedString = scanner.next();
System.out.println(decodeString(encodedStringLength, encodedString));
}
}
private static String decodeString(int encodedStringLength, String encodedString) {
StringBuilder decodedString = new StringBuilder();
int smallAAscii = 96;
for (int i = 0; i < encodedStringLength; i++) {
int currentInt = Character.getNumericValue(encodedString.charAt(i));
if (currentInt >= 3) {
char asciiString = (char) (currentInt + smallAAscii);
decodedString.append(asciiString);
} else {
if (i <= encodedStringLength - 3 && Character.getNumericValue(encodedString.charAt(i + 2)) == 0) {
if (i + 2 == encodedStringLength - 1 || Character.getNumericValue(encodedString.charAt(i + 3)) != 0) {
int firstCharInt = Character.getNumericValue(encodedString.charAt(i));
int secondCharInt = Character.getNumericValue(encodedString.charAt(i + 1));
String firstSecondString = String.valueOf(firstCharInt) + String.valueOf(secondCharInt);
char asciiString = (char) (Integer.parseInt(firstSecondString) + smallAAscii);
decodedString.append(asciiString);
i += 2;
} else {
char asciiString = (char) (currentInt + smallAAscii);
decodedString.append(asciiString);
}
} else {
char asciiString = (char) (currentInt + smallAAscii);
decodedString.append(asciiString);
}
}
}
return decodedString.toString();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 98acc9e14687103bdfdb99937fe2b2e1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
String temp="";
int len=sc.nextInt();
String t=sc.next();
int j=len-1;
while(j>=0){
if(t.charAt(j)=='0'){
temp+=(char)(96+((t.charAt(j-2)-48)*10+(t.charAt(j-1)-48)));
j=j-3;
}
else{
temp+=(char)(96+((t.charAt(j)-48)));
j--;
}
}
String main="";
for(int k=temp.length()-1;k>=0;k--)
main+=temp.charAt(k);
System.out.print(main);
System.out.println();
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | bb623a129b1caae765e7aaf70f27a8e0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
public class problemB {
public static Map<Integer, Character> dic = new HashMap<Integer, Character>();
public static void initialDictionary() {
for (char c = 'a'; c <= 'z'; c++) {
// System.out.println("checking: " + c + " " + (c - '0'- 48));
dic.put((c - '0' - 48), c);
}
}
public static void main(String[] args) {
initialDictionary();
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
String s = sc.next();
s = sc.next();
char[] a = s.toCharArray();
String numb;
String res = "";
for (int i = a.length - 1; i >= 0; i--) {
if (a[i] == '0') {
numb = s.substring(i - 2, i);
// System.out.println(Integer.parseInt(numb));
res = dic.get(Integer.parseInt(numb)) + res;
i = i - 2;
} else {
res = dic.get(Integer.parseInt(Character.toString(a[i]))) + res;
// System.out.println(a[i]);
}
}
System.out.println(res);
}
sc.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 4a1402115d7b4a68a9c34acd2982c85e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Solution {
public static boolean isPrime(int num){
if(num==0||num==1)
return false;
for(int i=2;i<=num/2;i++){
if(num%i==0)
return false;
}
return true;
}
public static long gcd(long a, long b)
{
if(b==0)
return a;
else
return gcd(b, a%b);
}
public static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
public static void solve(String s) {
StringBuilder sb=new StringBuilder();
for(int i=s.length()-1;i>=0;) {
if(s.charAt(i)!='0') {
String s1="";
s1+=s.charAt(i);
int t=Integer.parseInt(s1);
sb.append((char)(t+96));
i--;
}
else {
String p="";
p+=s.substring(i-2,i);
int t=Integer.parseInt(p);
sb.append((char)(t+96));
i=i-3;
}
}
System.out.println(sb.reverse());
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long t=sc.nextLong();
while(t-->0) {
int n=sc.nextInt();
String s=sc.next();
solve(s);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 8173142f9fd0aadadc18cb585b2d6d6c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Test {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0; i < t; i++) {
int n = in.nextInt();
String b = in.next();
StringBuilder stringBuilder = new StringBuilder();
for(int j = n - 1; j >= 0; j--) {
char c = b.charAt(j);
if(c != '0') {
stringBuilder.insert(0, (char) (c + 'a' - '0' - 1));
} else {
stringBuilder.insert(0, (char) ((b.charAt(j - 2) - '0') * 10 + b.charAt(j - 1) - '0' + 'a' - 1));
j = j - 2;
}
}
System.out.println(stringBuilder.toString());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 918689cbb70584de3d2e9d460defd4d5 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class B {
static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
static Scanner scanner=new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) {
int num = scanner.nextInt();
int c = 'a' - '0'-1;
while (num--!=0){
int n = scanner.nextInt();
String t = scanner.next();
List<String> list = new ArrayList<>();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i <=t.length(); i++) {
if (i==t.length()||(t.charAt(i)=='0'&&(i==t.length()-1||t.charAt(i+1)!='0'))){
list.add(stringBuilder.toString());
stringBuilder = new StringBuilder();
}else {
stringBuilder.append((char)t.charAt(i));
}
}
int length = list.size();
for (int i = 0; i < length; i++) {
int j =0;
String s = list.get(i);
if (i==length-1){
j = s.length();
for (int k = 0; k < j; k++) {
stringBuilder.append((char)(s.charAt(k)+c));
}
}else {
j = s.length()-2;
for (int k = 0; k < j; k++) {
stringBuilder.append((char)(s.charAt(k)+c));
}
stringBuilder.append((char)((s.charAt(j)-'0')*10+s.charAt(j+1)+c));
}
}
out.println(stringBuilder.toString());
}
out.flush();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ed01139863f5413442c82c7b6ee37a9a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class DecodeString {
public static void main(String[] args) {
int t,n;
String s;
StringBuilder sb,ans;
Scanner sc = new Scanner(System.in);
t=sc.nextInt();
while(t-->0){
n=sc.nextInt();
s=sc.next();
ans=new StringBuilder();
for(int i=n-1;i>=0;){
sb=new StringBuilder();
if(s.charAt(i)=='0')
{
i--;
sb.append(s.charAt(i-1));
sb.append(s.charAt(i));
ans.append((char)(Integer.parseInt(sb.toString())-1+'a'));
i-=2;
}
else
{
ans.append((char)(Integer.parseInt(s.charAt(i)+"")-1+'a'));
i--;
}
}
ans.reverse();
System.out.println(ans.toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 890cea9c39737ad615f67aa4d58cd54d | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
ArrayList<String> codes = new ArrayList<>();
while (t > 0) {
scan.nextInt();
String str = scan.next();
String code = "";
for (int i = 0; i < str.length(); i++) {
int num = 0;
if (i < str.length() - 3) {
// check the two next element if 0
if (str.charAt(i + 2) == '0') {
// check the third next element if 0
if (str.charAt(i + 3) == '0') {
num = Integer.parseInt(str.substring(i, i + 1));
} else {
num = Integer.parseInt(str.substring(i, i + 2));
i += 2;
}
} else {
num = Integer.parseInt(str.substring(i, i + 1));
}
} else if (i == str.length() - 3) {
if (str.charAt(i + 2) == '0') {
num = Integer.parseInt(str.substring(i, i + 2));
code += code(num);
break;
} else
num = Integer.parseInt(str.substring(i, i + 1));
} else
num = Integer.parseInt(str.substring(i, i + 1));
code += code(num);
}
codes.add(code);
t--;
}
for(String code: codes)
System.out.println(code);
/*
int x = 0;
while(true) {
System.out.println(x);
x++;
}
*/
/*
for(int i = 10; i <= 1000000; i++) {String num = Integer.toString(i);
for(int j = 0; j < num.length() - 1; j++) {
boolean check = false;
for (int k = j + 1; k < num.length(); k++)
if ((Integer.parseInt(num.substring(j, j + 1)) == 2 * Integer.parseInt(num.substring(k, k + 1))) || (2 * Integer.parseInt(num.substring(j, j + 1)) == Integer.parseInt(num.substring(k, k + 1)))) {
count++;
check = true;
break;
}
if(check)
break;
}
}
System.out.println(count);
*/
}
public static char code(int num) {
num--;
return (char)('a' + num);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c485bb81aadd83b7862443db3bfafd32 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args) throws IOException {
//Scanner in = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter("output.txt");
int t = nextInt();
for (int k = 0; k < t; k++) {
Stack<Character> a = new Stack<>();
int n = nextInt();
String s = next();
for (int i = n - 1; i >= 0;) {
if(s.charAt(i) == '0'){
a.push((char)((s.charAt(i - 2) - '0') * 10 + s.charAt(i - 1) - '0' + 'a' - 1));
i -= 3;
}else{
a.push((char)(s.charAt(i) - '0' + 'a' - 1));
i--;
}
}
while(!a.isEmpty()) out.print(a.pop());
out.println();
}
out.close();
}
static class Pair implements Comparable<Pair> {
int x, y, z;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if (x != o.x) return Integer.compare(x, o.x);
return Integer.compare(y, o.y);
}
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer in = new StringTokenizer("");
public static String next() throws IOException {
while (in == null || !in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public static int nextInt() throws IOException {
return Integer.parseInt(next());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ed7f7add76899743939cdbd2ce7c5405 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args) throws IOException {
//Scanner in = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter("output.txt");
int t = nextInt();
for (int k = 0; k < t; k++) {
Stack<Character> a = new Stack<>();
int n = nextInt();
String s = next();
for (int i = n - 1; i >= 0;) {
if(s.charAt(i) == '0'){
a.push((char)((s.charAt(i - 2) - '0') * 10 + s.charAt(i - 1) - '0' + 'a' - 1));
i -= 3;
}else{
a.push((char)(s.charAt(i) - '0' + 'a' - 1));
i--;
}
}
while(!a.isEmpty()) out.print(a.pop());
out.println();
}
out.close();
}
static class Pair implements Comparable<Pair> {
int x, y, z;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if (x != o.x) return Integer.compare(x, o.x);
return Integer.compare(y, o.y);
}
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer in = new StringTokenizer("");
public static String next() throws IOException {
while (in == null || !in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public static int nextInt() throws IOException {
return Integer.parseInt(next());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static long nextLong() throws IOException {
return Long.parseLong(next());
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 7fd31761adca84527766f2af7bdee3cc | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class abc{
public static void main(String[]args){
Scanner in=new Scanner(System.in);
int p= in.nextInt();
while(p-->0){
int n=in.nextInt();
String res="";
String t=in.next();
for(int i=n-1; i>=0; i--){
if(t.substring(i,i+1).compareTo("0")==0){
res = Character.toString((char) (Integer.parseInt(t.substring(i-2, i))+96) ) + res;
i -= 2;
}
else{
res = Character.toString((char) (Integer.parseInt(t.substring(i, i+1))+96) ) + res;
}
}
System.out.println(res);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 2a5d3c2586204411392349b3d5ea2152 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // package faltu;
import java.util.*;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
public class Main {
// ***********************MATHS--STARTS************************************************* //
private static ArrayList<Long> get_divisor(long x) {
ArrayList<Long>a=new ArrayList<Long>();
for(long i=2;i*i<=x;i++) {
if(x%i==0) {
a.add((long) i);
if(x/i!=i)a.add(x/i);
}
}
return a;
}
private static int CntOfFactor(long x) {
ArrayList<Long>a=new ArrayList<Long>();
for(long i=1;i*i<=x;i++) {
if(x%i==0) {
a.add((long) i);
if(x/i!=i)a.add(x/i);
}
}
return a.size();
}
static long[] sieve;
static long[] smallestPrime;
public static void sieve()
{
int n=4000000+1;
sieve=new long[n];
smallestPrime=new long[n];
sieve[0]=1;
sieve[1]=1;
for(int i=2;i<n;i++){
sieve[i]=i;
smallestPrime[i]=i;
}
for(int i=2;i*i<n;i++){
if(sieve[i]==i){
for(int j=i*i;j<n;j+=i){
if(sieve[j]==j)sieve[j]=1;
if(smallestPrime[j]==j||smallestPrime[j]>i)smallestPrime[j]=i;
}
}
}
}
static long nCr(long n,long r,long MOD) {
computeFact(n, MOD);
if(n<r)return 0;
if(r==0)return 1;
return fact[(int) n]*mod_inv(fact[(int) r],MOD)%MOD*mod_inv(fact[(int) (n-r)],MOD)%MOD;
}
static long[]fact;
static void computeFact(long n,long MOD) {
fact=new long[(int)n+1];
fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i%MOD)%MOD;
}
static long bin_expo(long a,long b,long MOD) {
if(b == 0)return 1;
long ans = bin_expo(a,b/2,MOD);
ans = (ans*ans)%MOD;
if(b % 2!=0){
ans = (ans*a)%MOD;
}
return ans%MOD;
}
static int ceil(int x, int y) {return (x % y == 0 ? x / y : (x / y + 1));}
static long ceil(long x, long y) {return (x % y == 0 ? x / y : (x / y + 1));}
static long mod_add(long a, long b, long m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
static long mod_mul(long a, long b, long m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
static long mod_sub(long a, long b, long m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
static long mod_inv(long n,long p) {return bin_expo(n,p-2,p);}
static long gcd(long a, long b){if (a == 0) {return b;}return gcd(b % a, a); }
static int gcd(int a, int b){if (a == 0) {return b; }return gcd(b % a, a); }
static long lcm(long a,long b){return (a / gcd(a, b)) * b;}
static long min(long x,long y) {return Math.min(x, y);}static long max(long x,long y) {return Math.max(x, y);}
static int min(int x,int y) {return Math.min(x, y);}static int max(int x,int y) {return Math.max(x, y);}
static ArrayList<String>powof2s;
static void powof2S() {
long i=1;
while(i<(long)2e18) {
powof2s.add(String.valueOf(i));
i*=2;
}
}
static long power(long a, long b){
a %=MOD;long out = 1;
while (b > 0) {
if((b&1)!=0)out = out * a % MOD;
a = a * a % MOD;
b >>= 1;
a*=a;
}
return out;
}
static boolean coprime(int a, long l){return (gcd(a, l) == 1);}
// ****************************MATHS-ENDS*****************************************************
// ***********************BINARY-SEARCH STARTS***********************************************
public static int upperBound(long[] arr, long m, int l, int r) {
while(l<=r) {
int mid=(l+r)/2;
if(arr[mid]<=m) l=mid+1;
else r=mid-1;
}
return l;
}
public static int lowerBound(long[] a, long m, int l, int r) {
while(l<=r) {
int mid=(l+r)/2;
if(a[mid]<m) l=mid+1;
else r=mid-1;
}
return l;
}
public static int lowerBound(ArrayList<Integer> ar,int k){
int s=0,e=ar.size();
while (s!=e){
int mid = s+e>>1;
if (ar.get(mid) <k)s=mid+1;
else e=mid;
}
if(s==ar.size())return -1;
return s;
}
public static int upperBound(ArrayList<Integer> ar,int k){
int s=0,e=ar.size();
while (s!=e){
int mid = s+e>>1;
if (ar.get(mid) <=k)s=mid+1;
else e=mid;
}
if(s==ar.size())return -1;
return s;
}
public static long getClosest(long val1, long val2,long target){if (target - val1 >= val2 - target)return val2; else return val1;}
static void ruffleSort(long[] a) {
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
long oi=r.nextInt(n), temp=a[i];
a[i]=a[(int)oi];
a[(int)oi]=temp;
}
Arrays.sort(a);
}
static void ruffleSort(int[] a){
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
int oi=r.nextInt(n), temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
Arrays.sort(a);
}
int ceilIndex(int input[], int T[], int end, int s){
int start = 0;
int middle;
int len = end;
while(start <= end){
middle = (start + end)/2;
if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){
return middle+1;
}else if(input[T[middle]] < s){
start = middle+1;
}else{
end = middle-1;
}
}
return -1;
}
static int lowerLimitBinarySearch(ArrayList<Long> v,long k) {
int n =v.size();
int first = 0,second = n;
while(first <second) {
int mid = first + (second-first)/2;
if(v.get(mid) > k) {
second = mid;
}else {
first = mid+1;
}
}
if(first < n && v.get(first) < k) {
first++;
}
return first; //1 index
}
public static int searchindex(long arr[], long t){int index = Arrays.binarySearch(arr, t);return (index < 0) ? -1 : index;}
public static long[] sort(long[] a) {ArrayList<Long> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;}
public static int[] sort(int[] a) {ArrayList<Integer> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;}
// *******************************BINARY-SEARCH ENDS***********************************************
// *********************************GRAPHS-STARTS****************************************************
// *******----SEGMENT TREE IMPLEMENT---*****
// -------------START---------------
void buildTree (int[] arr,int[] tree,int start,int end,int treeNode){
if(start==end){
tree[treeNode]=arr[start];
return;
}
buildTree(arr,tree,start,end,2*treeNode);
buildTree(arr,tree,start,end,2*treeNode+1);
tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1];
}
void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value){
if(start==end){
arr[idx]=value;
tree[treeNode]=value;
return;
}
int mid=(start+end)/2;
if(idx>mid)updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value);
else updateTree(arr,tree,start,mid,2*treeNode,idx,value);
tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
}
long query(int[]arr,int[]tree,int start,int end,int treeNode,int qleft,int qright) {
if(start>=qleft&&end<=qright)return tree[treeNode];
if(start>qright||end<qleft)return 0;
int mid=(start+end)/2;
long valLeft=query(arr,tree,start,mid-1,treeNode*2,qleft,qright);
long valRight=query(arr,tree,mid+1,end,treeNode*2+1,qleft,qright);
return valLeft+valRight;
}
// -------------ENDS---------------
//***********************DSU IMPLEMENT START*************************
static int parent[];
static int rank[];
static int[]Size;
static void makeSet(int n){
parent=new int[n];
rank=new int[n];
Size=new int[n];
for(int i=0;i<n;i++){
parent[i]=i;
rank[i]=0;
Size[i]=1;
}
}
static void union(int u,int v){
u=findpar(u);
v=findpar(v);
if(u==v)return;
if(rank[u]<rank[v]) {
parent[u]=v;
Size[v]+=Size[u];
}
else if(rank[v]<rank[u]) {
parent[v]=u;
Size[u]+=Size[v];
}
else{
parent[v]=u;
rank[u]++;
Size[u]+=Size[v];
}
}
private static int findpar(int node){
if(node==parent[node])return node;
return parent[node]=findpar(parent[node]);
}
// *********************DSU IMPLEMENT ENDS*************************
// ****__________PRIMS ALGO______________________****
private static int prim(ArrayList<node>[] adj,int N,int node) {
int key[] = new int[N+1];
int parent[] = new int[N+1];
boolean mstSet[] = new boolean[N+1];
for(int i = 0;i<N;i++) {
key[i] = 100000000;
mstSet[i] = false;
}
PriorityQueue<node> pq = new PriorityQueue<node>(N, new node());
key[node] = 0;
parent[node] = -1;
pq.add(new node( node,key[node]));
for(int i = 0;i<N-1;i++) {
int u = pq.poll().getV();
mstSet[u] = true;
for(node it: adj[u]) {
if(mstSet[it.getV()] == false && it.getW() < key[it.getV()]) {
parent[it.getV()] = u;
key[it.getV()] = (int) it.getW();
pq.add(new node(it.getV(), key[it.getV()]));
}
}
}
int sum=0;
for(int i=1;i<N;i++) {
System.out.println(key[i]);
sum+=key[i];
}
System.out.println(sum);
return sum;
}
// ****____________DIJKSTRAS ALGO___________****
static int[]dist;
static int dijkstra(int u,int n,ArrayList<node>adj[]) {
dist=new int[n];
Arrays.fill(dist,Integer.MAX_VALUE);
dist[u]=0;
PriorityQueue<node>pq=new PriorityQueue<node>(new node());
pq.add(new node(u,0));
while(!pq.isEmpty()) {
node v=pq.poll();
for(node it:adj[v.getV()]) {
if(dist[it.getV()]>it.getW()+dist[v.getV()]) {
dist[it.getV()]=(int) (it.getW()+dist[v.getV()]);
pq.add(new node(it.getV(),dist[it.getV()]));
}
}
}
int sum=0;
for(int i=1;i<n;i++){
System.out.println(dist[i]);
sum+=dist[i];
}
return sum;
}
private static void setGraph(int n,int m){
vis=new boolean[n+1];
indeg=new int[n+1];
// adj=new ArrayList<ArrayList<Integer>>();
// for(int i=0;i<=n;i++)adj.add(new ArrayList<>());
// for(int i=0;i<m;i++){
// int u=s.nextInt(),v=s.nextInt();
// adj.get(u).add(v);
// adj.get(v).add(u);
// }
adj=new ArrayList[n+1];
// backadj=new ArrayList[n+1];
for(int i=0;i<=n;i++){
adj[i]=new ArrayList<Integer>();
// backadj[i]=new ArrayList<Integer>();
}
for(int i=0;i<m;i++){
int u=s.nextInt(),v=s.nextInt();
adj[u].add(v);
adj[v].add(u);
// backadj[v].add(u);
indeg[v]++;
indeg[u]++;
}
// weighted adj
// adj=new ArrayList[n+1];
// for(int i=0;i<=n;i++){
// adj[i]=new ArrayList<node>();
// }
// for(int i=0;i<m;i++){
// int u=s.nextInt(),v=s.nextInt();
// long w=s.nextInt();
// adj[u].add(new node(v,w));
//// adj[v].add(new node(u,w));
// }
}
// *********************************GRAPHS-ENDS****************************************************
static int[][] dirs8 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
static int[][] dirs4 = {{1,0},{-1,0},{0,1},{0,-1}}; //d-u-r-l
static long MOD=(long) (1e9+7);
static int prebitsum[][];
static boolean[] vis;
static int[]indeg;
// static ArrayList<ArrayList<Integer>>adj;
static ArrayList<Integer> adj[];
static ArrayList<Integer> backadj[];
static FastReader s = new FastReader(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException
{
// sieve();
// computeFact((int)1e7+1,MOD);
// prebitsum=new int[2147483648][31];
// presumbit(prebitsum);
// powof2S();
//
// try {
int tt = s.nextInt();
// int tt=1;
for(int i=1;i<=tt;i++) {
solver();
}
out.close();
// catch(Exception e) {return;}
}
private static void solver() {
int n=s.nextInt();
char[] str=s.next().toCharArray();
String ans = "";
for(int i=n-1;i>=0;i--) {
if(str[i]=='0') {
--i;
int t=str[i]-'0';
--i;
t+=(str[i]-'0')*10;
ans = ((char)(t+'a'-1))+ans;
}
else{
ans = ((char)(str[i]-'0'+'a'-1))+ans;
}
}
out.println(ans);
}
/* *********************BITS && TOOLS &&DEBUG STARTS***********************************************/
static boolean issafe(int i, int j, int r,int c,boolean[][]vis){
if (i < 0 || j < 0 || i >= r || j >= c||vis[i][j]==true)return false;
else return true;
}
static void presumbit(int[][]prebitsum) {
for(int i=1;i<=200000;i++) {
int z=i;
int j=0;
while(z>0) {
if((z&1)==1) {
prebitsum[i][j]+=(prebitsum[i-1][j]+1);
}else {
prebitsum[i][j]=prebitsum[i-1][j];
}
z=z>>1;
j++;
}
}
}
static void countOfSetBit(long[]a) {
for(int j=30;j>=0;j--) {
int cnt=0;
for(long i:a) {
if((i&1<<j)==1)cnt++;
}
// printing the current no set bit in all array element
System.out.println(cnt);
}
}
public static String revStr(String str){String input = str;StringBuilder input1 = new StringBuilder();input1.append(input);input1.reverse();return input1.toString();}
static void printA(long[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();}
static void printA(int[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();}
static void pc2d(boolean[][] vis) {
int n=vis.length;
int m=vis[0].length;
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
System.out.print(vis[i][j]+" ");
}
System.out.println();
}
}
static void pi2d(char[][] a) {
int n=a.length;
int m=a[0].length;
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
static void p1d(int[]a) {
for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");
System.out.println();
}
// *****************BITS && TOOLS &&DEBUG ENDS***********************************************
}
// **************************I/O*************************
class FastReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = null;}
public String next() {while (tokenizer == null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(reader.readLine());} catch (IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();}
public int nextInt(){ return Integer.parseInt(next());}
public long nextLong() {return Long.parseLong(next());}
public double nextDouble() {return Double.parseDouble(next());}
public String nextLine() {String str = "";try {str = reader.readLine();}catch (IOException e) {e.printStackTrace();}return str;}
public int[] rdia(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = nextInt();return a;}
public long[] rdla(int n) {long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;}
public Integer[] rdIa(int n) {Integer[] a = new Integer[n];for (int i = 0; i < n; i++) a[i] =nextInt();return a;}
public Long[] rdLa(int n) {Long[] a = new Long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;}
}
class dsu{
int n;
static int parent[];
static int rank[];
static int[]Size;
public dsu(int n) {this.n=n;this.parent=new int[n];this.rank=new int[n];this.Size=new int[n];
for(int i=0;i<n;i++){parent[i]=i;rank[i]=0;Size[i]=1;}
}
static int findpar(int node) {if(node==parent[node])return node;return parent[node]=findpar(parent[node]);}
static void union(int u,int v){
u=findpar(u);v=findpar(v);
if(u!=v) {
if(rank[u]<rank[v]) {parent[u]=v;Size[v]+=Size[u];}
else if(rank[v]<rank[u]) {parent[v]=u;Size[u]+=Size[v];}
else{parent[v]=u;rank[u]++;Size[u]+=Size[v];}
}
}
}
class pair{
int x;int y;
long u,v;
public pair(int x,int y){this.x=x;this.y=y;}
public pair(long u,long v) {this.u=u;this.v=v;}
}
class node implements Comparator<node>{
private int v;
private long w;
node(int _v, long _w) { v = _v; w = _w; }
node() {}
int getV() { return v; }
long getW() { return w; }
@Override
public int compare(node node1, node node2) {
if (node1.w < node2.w) return -1;
if (node1.w > node2.w) return 1;
return 0;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 6613e06bc28c32f3fa6b780ba24365c1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // package faltu;
import java.util.*;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
public class Main {
// ***********************MATHS--STARTS************************************************* //
private static ArrayList<Long> get_divisor(long x) {
ArrayList<Long>a=new ArrayList<Long>();
for(long i=2;i*i<=x;i++) {
if(x%i==0) {
a.add((long) i);
if(x/i!=i)a.add(x/i);
}
}
return a;
}
private static int CntOfFactor(long x) {
ArrayList<Long>a=new ArrayList<Long>();
for(long i=1;i*i<=x;i++) {
if(x%i==0) {
a.add((long) i);
if(x/i!=i)a.add(x/i);
}
}
return a.size();
}
static long[] sieve;
static long[] smallestPrime;
public static void sieve()
{
int n=4000000+1;
sieve=new long[n];
smallestPrime=new long[n];
sieve[0]=1;
sieve[1]=1;
for(int i=2;i<n;i++){
sieve[i]=i;
smallestPrime[i]=i;
}
for(int i=2;i*i<n;i++){
if(sieve[i]==i){
for(int j=i*i;j<n;j+=i){
if(sieve[j]==j)sieve[j]=1;
if(smallestPrime[j]==j||smallestPrime[j]>i)smallestPrime[j]=i;
}
}
}
}
static long nCr(long n,long r,long MOD) {
computeFact(n, MOD);
if(n<r)return 0;
if(r==0)return 1;
return fact[(int) n]*mod_inv(fact[(int) r],MOD)%MOD*mod_inv(fact[(int) (n-r)],MOD)%MOD;
}
static long[]fact;
static void computeFact(long n,long MOD) {
fact=new long[(int)n+1];
fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i%MOD)%MOD;
}
static long bin_expo(long a,long b,long MOD) {
if(b == 0)return 1;
long ans = bin_expo(a,b/2,MOD);
ans = (ans*ans)%MOD;
if(b % 2!=0){
ans = (ans*a)%MOD;
}
return ans%MOD;
}
static int ceil(int x, int y) {return (x % y == 0 ? x / y : (x / y + 1));}
static long ceil(long x, long y) {return (x % y == 0 ? x / y : (x / y + 1));}
static long mod_add(long a, long b, long m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
static long mod_mul(long a, long b, long m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
static long mod_sub(long a, long b, long m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
static long mod_inv(long n,long p) {return bin_expo(n,p-2,p);}
static long gcd(long a, long b){if (a == 0) {return b;}return gcd(b % a, a); }
static int gcd(int a, int b){if (a == 0) {return b; }return gcd(b % a, a); }
static long lcm(long a,long b){return (a / gcd(a, b)) * b;}
static long min(long x,long y) {return Math.min(x, y);}static long max(long x,long y) {return Math.max(x, y);}
static int min(int x,int y) {return Math.min(x, y);}static int max(int x,int y) {return Math.max(x, y);}
static ArrayList<String>powof2s;
static void powof2S() {
long i=1;
while(i<(long)2e18) {
powof2s.add(String.valueOf(i));
i*=2;
}
}
static long power(long a, long b){
a %=MOD;long out = 1;
while (b > 0) {
if((b&1)!=0)out = out * a % MOD;
a = a * a % MOD;
b >>= 1;
a*=a;
}
return out;
}
static boolean coprime(int a, long l){return (gcd(a, l) == 1);}
// ****************************MATHS-ENDS*****************************************************
// ***********************BINARY-SEARCH STARTS***********************************************
public static int upperBound(long[] arr, long m, int l, int r) {
while(l<=r) {
int mid=(l+r)/2;
if(arr[mid]<=m) l=mid+1;
else r=mid-1;
}
return l;
}
public static int lowerBound(long[] a, long m, int l, int r) {
while(l<=r) {
int mid=(l+r)/2;
if(a[mid]<m) l=mid+1;
else r=mid-1;
}
return l;
}
public static int lowerBound(ArrayList<Integer> ar,int k){
int s=0,e=ar.size();
while (s!=e){
int mid = s+e>>1;
if (ar.get(mid) <k)s=mid+1;
else e=mid;
}
if(s==ar.size())return -1;
return s;
}
public static int upperBound(ArrayList<Integer> ar,int k){
int s=0,e=ar.size();
while (s!=e){
int mid = s+e>>1;
if (ar.get(mid) <=k)s=mid+1;
else e=mid;
}
if(s==ar.size())return -1;
return s;
}
public static long getClosest(long val1, long val2,long target){if (target - val1 >= val2 - target)return val2; else return val1;}
static void ruffleSort(long[] a) {
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
long oi=r.nextInt(n), temp=a[i];
a[i]=a[(int)oi];
a[(int)oi]=temp;
}
Arrays.sort(a);
}
static void ruffleSort(int[] a){
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
int oi=r.nextInt(n), temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
Arrays.sort(a);
}
int ceilIndex(int input[], int T[], int end, int s){
int start = 0;
int middle;
int len = end;
while(start <= end){
middle = (start + end)/2;
if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){
return middle+1;
}else if(input[T[middle]] < s){
start = middle+1;
}else{
end = middle-1;
}
}
return -1;
}
static int lowerLimitBinarySearch(ArrayList<Long> v,long k) {
int n =v.size();
int first = 0,second = n;
while(first <second) {
int mid = first + (second-first)/2;
if(v.get(mid) > k) {
second = mid;
}else {
first = mid+1;
}
}
if(first < n && v.get(first) < k) {
first++;
}
return first; //1 index
}
public static int searchindex(long arr[], long t){int index = Arrays.binarySearch(arr, t);return (index < 0) ? -1 : index;}
public static long[] sort(long[] a) {ArrayList<Long> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;}
public static int[] sort(int[] a) {ArrayList<Integer> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;}
// *******************************BINARY-SEARCH ENDS***********************************************
// *********************************GRAPHS-STARTS****************************************************
// *******----SEGMENT TREE IMPLEMENT---*****
// -------------START---------------
void buildTree (int[] arr,int[] tree,int start,int end,int treeNode){
if(start==end){
tree[treeNode]=arr[start];
return;
}
buildTree(arr,tree,start,end,2*treeNode);
buildTree(arr,tree,start,end,2*treeNode+1);
tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1];
}
void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value){
if(start==end){
arr[idx]=value;
tree[treeNode]=value;
return;
}
int mid=(start+end)/2;
if(idx>mid)updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value);
else updateTree(arr,tree,start,mid,2*treeNode,idx,value);
tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
}
long query(int[]arr,int[]tree,int start,int end,int treeNode,int qleft,int qright) {
if(start>=qleft&&end<=qright)return tree[treeNode];
if(start>qright||end<qleft)return 0;
int mid=(start+end)/2;
long valLeft=query(arr,tree,start,mid-1,treeNode*2,qleft,qright);
long valRight=query(arr,tree,mid+1,end,treeNode*2+1,qleft,qright);
return valLeft+valRight;
}
// -------------ENDS---------------
//***********************DSU IMPLEMENT START*************************
static int parent[];
static int rank[];
static int[]Size;
static void makeSet(int n){
parent=new int[n];
rank=new int[n];
Size=new int[n];
for(int i=0;i<n;i++){
parent[i]=i;
rank[i]=0;
Size[i]=1;
}
}
static void union(int u,int v){
u=findpar(u);
v=findpar(v);
if(u==v)return;
if(rank[u]<rank[v]) {
parent[u]=v;
Size[v]+=Size[u];
}
else if(rank[v]<rank[u]) {
parent[v]=u;
Size[u]+=Size[v];
}
else{
parent[v]=u;
rank[u]++;
Size[u]+=Size[v];
}
}
private static int findpar(int node){
if(node==parent[node])return node;
return parent[node]=findpar(parent[node]);
}
// *********************DSU IMPLEMENT ENDS*************************
// ****__________PRIMS ALGO______________________****
private static int prim(ArrayList<node>[] adj,int N,int node) {
int key[] = new int[N+1];
int parent[] = new int[N+1];
boolean mstSet[] = new boolean[N+1];
for(int i = 0;i<N;i++) {
key[i] = 100000000;
mstSet[i] = false;
}
PriorityQueue<node> pq = new PriorityQueue<node>(N, new node());
key[node] = 0;
parent[node] = -1;
pq.add(new node( node,key[node]));
for(int i = 0;i<N-1;i++) {
int u = pq.poll().getV();
mstSet[u] = true;
for(node it: adj[u]) {
if(mstSet[it.getV()] == false && it.getW() < key[it.getV()]) {
parent[it.getV()] = u;
key[it.getV()] = (int) it.getW();
pq.add(new node(it.getV(), key[it.getV()]));
}
}
}
int sum=0;
for(int i=1;i<N;i++) {
System.out.println(key[i]);
sum+=key[i];
}
System.out.println(sum);
return sum;
}
// ****____________DIJKSTRAS ALGO___________****
static int[]dist;
static int dijkstra(int u,int n,ArrayList<node>adj[]) {
dist=new int[n];
Arrays.fill(dist,Integer.MAX_VALUE);
dist[u]=0;
PriorityQueue<node>pq=new PriorityQueue<node>(new node());
pq.add(new node(u,0));
while(!pq.isEmpty()) {
node v=pq.poll();
for(node it:adj[v.getV()]) {
if(dist[it.getV()]>it.getW()+dist[v.getV()]) {
dist[it.getV()]=(int) (it.getW()+dist[v.getV()]);
pq.add(new node(it.getV(),dist[it.getV()]));
}
}
}
int sum=0;
for(int i=1;i<n;i++){
System.out.println(dist[i]);
sum+=dist[i];
}
return sum;
}
private static void setGraph(int n,int m){
vis=new boolean[n+1];
indeg=new int[n+1];
// adj=new ArrayList<ArrayList<Integer>>();
// for(int i=0;i<=n;i++)adj.add(new ArrayList<>());
// for(int i=0;i<m;i++){
// int u=s.nextInt(),v=s.nextInt();
// adj.get(u).add(v);
// adj.get(v).add(u);
// }
adj=new ArrayList[n+1];
// backadj=new ArrayList[n+1];
for(int i=0;i<=n;i++){
adj[i]=new ArrayList<Integer>();
// backadj[i]=new ArrayList<Integer>();
}
for(int i=0;i<m;i++){
int u=s.nextInt(),v=s.nextInt();
adj[u].add(v);
adj[v].add(u);
// backadj[v].add(u);
indeg[v]++;
indeg[u]++;
}
// weighted adj
// adj=new ArrayList[n+1];
// for(int i=0;i<=n;i++){
// adj[i]=new ArrayList<node>();
// }
// for(int i=0;i<m;i++){
// int u=s.nextInt(),v=s.nextInt();
// long w=s.nextInt();
// adj[u].add(new node(v,w));
//// adj[v].add(new node(u,w));
// }
}
// *********************************GRAPHS-ENDS****************************************************
static int[][] dirs8 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
static int[][] dirs4 = {{1,0},{-1,0},{0,1},{0,-1}}; //d-u-r-l
static long MOD=(long) (1e9+7);
static int prebitsum[][];
static boolean[] vis;
static int[]indeg;
// static ArrayList<ArrayList<Integer>>adj;
static ArrayList<Integer> adj[];
static ArrayList<Integer> backadj[];
static FastReader s = new FastReader(System.in);
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException
{
// sieve();
// computeFact((int)1e7+1,MOD);
// prebitsum=new int[2147483648][31];
// presumbit(prebitsum);
// powof2S();
//
// try {
int tt = s.nextInt();
// int tt=1;
for(int i=1;i<=tt;i++) {
solver();
}
out.close();
// catch(Exception e) {return;}
}
private static void solver() {
int n=s.nextInt();
char[] str=s.next().toCharArray();
String ans = "";
for(int i=n-1;i>=0;i--) {
if(str[i]=='0') {
i--;
int t=str[i]-'0';
i--;
t+=(str[i]-'0')*10;
ans = ((char)(t+'a'-1))+ans;
}
else{
ans = ((char)(str[i]-'0'+'a'-1))+ans;
}
}
out.println(ans);
}
/* *********************BITS && TOOLS &&DEBUG STARTS***********************************************/
static boolean issafe(int i, int j, int r,int c,boolean[][]vis){
if (i < 0 || j < 0 || i >= r || j >= c||vis[i][j]==true)return false;
else return true;
}
static void presumbit(int[][]prebitsum) {
for(int i=1;i<=200000;i++) {
int z=i;
int j=0;
while(z>0) {
if((z&1)==1) {
prebitsum[i][j]+=(prebitsum[i-1][j]+1);
}else {
prebitsum[i][j]=prebitsum[i-1][j];
}
z=z>>1;
j++;
}
}
}
static void countOfSetBit(long[]a) {
for(int j=30;j>=0;j--) {
int cnt=0;
for(long i:a) {
if((i&1<<j)==1)cnt++;
}
// printing the current no set bit in all array element
System.out.println(cnt);
}
}
public static String revStr(String str){String input = str;StringBuilder input1 = new StringBuilder();input1.append(input);input1.reverse();return input1.toString();}
static void printA(long[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();}
static void printA(int[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();}
static void pc2d(boolean[][] vis) {
int n=vis.length;
int m=vis[0].length;
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
System.out.print(vis[i][j]+" ");
}
System.out.println();
}
}
static void pi2d(char[][] a) {
int n=a.length;
int m=a[0].length;
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
static void p1d(int[]a) {
for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");
System.out.println();
}
// *****************BITS && TOOLS &&DEBUG ENDS***********************************************
}
// **************************I/O*************************
class FastReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = null;}
public String next() {while (tokenizer == null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(reader.readLine());} catch (IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();}
public int nextInt(){ return Integer.parseInt(next());}
public long nextLong() {return Long.parseLong(next());}
public double nextDouble() {return Double.parseDouble(next());}
public String nextLine() {String str = "";try {str = reader.readLine();}catch (IOException e) {e.printStackTrace();}return str;}
public int[] rdia(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = nextInt();return a;}
public long[] rdla(int n) {long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;}
public Integer[] rdIa(int n) {Integer[] a = new Integer[n];for (int i = 0; i < n; i++) a[i] =nextInt();return a;}
public Long[] rdLa(int n) {Long[] a = new Long[n];for (int i = 0; i < n; i++) a[i] = nextLong();return a;}
}
class dsu{
int n;
static int parent[];
static int rank[];
static int[]Size;
public dsu(int n) {this.n=n;this.parent=new int[n];this.rank=new int[n];this.Size=new int[n];
for(int i=0;i<n;i++){parent[i]=i;rank[i]=0;Size[i]=1;}
}
static int findpar(int node) {if(node==parent[node])return node;return parent[node]=findpar(parent[node]);}
static void union(int u,int v){
u=findpar(u);v=findpar(v);
if(u!=v) {
if(rank[u]<rank[v]) {parent[u]=v;Size[v]+=Size[u];}
else if(rank[v]<rank[u]) {parent[v]=u;Size[u]+=Size[v];}
else{parent[v]=u;rank[u]++;Size[u]+=Size[v];}
}
}
}
class pair{
int x;int y;
long u,v;
public pair(int x,int y){this.x=x;this.y=y;}
public pair(long u,long v) {this.u=u;this.v=v;}
}
class node implements Comparator<node>{
private int v;
private long w;
node(int _v, long _w) { v = _v; w = _w; }
node() {}
int getV() { return v; }
long getW() { return w; }
@Override
public int compare(node node1, node node2) {
if (node1.w < node2.w) return -1;
if (node1.w > node2.w) return 1;
return 0;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 464b2d0683766b24ee7564e85922b7a8 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0){
int n=in.nextInt();
String p=in.next();
String ans="";
int[] s=new int[n];
for(int i=0; i<n; i++){
s[i]=(int)(p.charAt(i)-48);
}
int k=0;
String[] a={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
for(int i=0; i<n; i++){
if(i+2<n && s[i+2]==0){
if(i+3<n && s[i+3]==0){
ans+=a[s[i]-1];
continue;
}
k=(int)((s[i]*10)+s[i+1]);
ans+=a[k-1];
i+=2;
continue;
}
else {
ans+=a[(s[i])-1];
continue;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | f52c1fcb3290905264332d5a6a4faf8c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static int gcd(int no, int sum) {
if (sum == 0)
return no;
return gcd(sum, no % sum);
}
static int lcm(int a , int b){
return (a / gcd(a , b))*b;
}
static void countSort(int[] arr)
{
int max = Arrays.stream(arr).max().getAsInt();
int min = Arrays.stream(arr).min().getAsInt();
int range = max - min + 1;
int count[] = new int[range];
int output[] = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
count[arr[i] - min]++;
}
for (int i = 1; i < count.length; i++) {
count[i] += count[i - 1];
}
for (int i = arr.length - 1; i >= 0; i--) {
output[count[arr[i] - min] - 1] = arr[i];
count[arr[i] - min]--;
}
for (int i = 0; i < arr.length; i++) {
arr[i] = output[i];
}
}
static void RandomShuffleSort(int [] a , int start , int end){
Random random = new Random();
for(int i = start; i<end; i++){
int j = random.nextInt(end);
int temp = a[j];
a[j] = a[i];
a[i] = temp;
}
Arrays.sort(a , start , end);
}
public static void main(String[] args) throws IOException , ParseException{
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(System.out));
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
String s = sc.nextLine();
String ans = "";
for(int i = n-1; i>=0;i--){
if(s.charAt(i) == '0'){
int nums = 10*(s.charAt(i-2)-'0') + (s.charAt(i-1)-'0');
ans=Character.toString((char)(96+nums)) + ans;
i-=2;
}
else {
int nums = s.charAt(i) - '0';
ans = Character.toString((char)(96+nums)) + ans;
}
}
System.out.println(ans);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 66ee8a8356261e7e8070ffec99602c29 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main{
public static void main(String [] args) throws IOException {
Scanner sc = new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = sc.nextInt() ;
StringBuilder res = new StringBuilder() ;
while(t-->0) {
int n = sc.nextInt() ;
String s = sc.next() ;
for(int i = s.length()-1 ; i>=0 ; i--) {
String h = "" ;
if(s.charAt(i) == '0') {
h+= s.charAt(i-1);
h = s.charAt(i-2) + h ;
i-=2 ;
res.append((char)(Integer.parseInt(h)-1 + 'a'));
// System.out.println(res.toString());
}
else {
h+= s.charAt(i);
res.append((char)(Integer.parseInt(h)-1 + 'a'));
// System.out.println(res.toString());
}
}
res.reverse() ;
System.out.println(res.toString());
res = new StringBuilder() ;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 7eb65930cc5f031a4e347fd9d81ff4d2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;
import static java.lang.System.out;
import static java.lang.Math.*;
public class pre294 {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static class MultiSet<K> {
TreeMap<K, Integer> map;
MultiSet() {
map = new TreeMap<>();
}
void add(K a) {
map.put(a, map.getOrDefault(a, 0) + 1);
}
boolean contains(K a) {
return map.containsKey(a);
}
void remove(K a) {
map.put(a, map.get(a) - 1);
if (map.get(a) == 0) map.remove(a);
}
int occrence(K a) {
return map.get(a);
}
K floor(K a) {
return map.floorKey(a);
}
K ceil(K a) {
return map.ceilingKey(a);
}
@Override
public String toString() {
ArrayList<K> set = new ArrayList<>();
for (Map.Entry<K, Integer> i : map.entrySet()) {
for (int j = 1; j <= i.getValue(); j++) set.add(i.getKey());
}
return set.toString();
}
}
static class Pair<K, V> {
K value1;
V value2;
Pair(K a, V b) {
value1 = a;
value2 = b;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pair)) return false;
Pair<?, ?> p = (Pair<?, ?>) o;
return Objects.equals(this.value1, p.value1) && Objects.equals(this.value2, p.value2);
}
@Override
public int hashCode() {
int result = this.value1.hashCode();
result = 31 * result + this.value2.hashCode();
return result;
}
@Override
public String toString() {
return ("[" + value1 + " <=> " + value2 + "]");
}
}
static ArrayList<Integer> primes;
static void setPrimes(int n) {
boolean p[] = new boolean[n];
Arrays.fill(p, true);
for (int i = 2; i < p.length; i++) {
if (p[i]) {
primes.add(i);
for (int j = i * 2; j < p.length; j += i) p[j] = false;
}
}
}
static int mod = (int) (1e9 + 7);
static int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
public static void main(String args[]) {
FastReader obj = new FastReader();
int tc = obj.nextInt();
while(tc--!=0){
int n = obj.nextInt();
char str[] = obj.next().toCharArray();
StringBuffer ans = new StringBuffer();
for(int i=n-1;i>=0;){
if(str[i]=='0'){
int a = (str[i-2]-'0');
int b = (str[i-1]-'0');
ans.append((char)(a*10+b+'a'-1));
i-=3;
}else {
ans.append((char)((str[i]-'0')+'a'-1));
i--;
}
}
//out.println(ans);
//for(int i=ans.length()-1;i>=0;i--) out.print(ans.charAt(i));
out.println(ans.reverse());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 8014c8505022dd975383fc8988f4e682 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static InputReader sc;
static OutputWriter out;
private static final int maxn = (int)(1e5 + 7);
// public static long ask(int a, int b) throws Exception {
// out.println("? " + a + " " + b);
// out.flush();
// return sc.nextLong();
// }
public static boolean multiCase() throws Exception {
return true;
}
public static void solve() throws Exception {
int len=sc.nextInt();
int pos = 0;
char[] str=(" "+sc.next()).toCharArray();
String ans = "";
for(int i=len;i>0;i--) {
if(str[i]=='0') {
i--;
int t=str[i]-'0';
i--;
t+=(str[i]-'0')*10;
ans += ((char)(t+'a'-1));
pos++;
}
else{
ans += ((char)(str[i]-'0'+'a'-1));
pos ++;
}
}
char[] ansCharArray = ans.toCharArray();
for(int i = pos - 1; i >= 0; i -- ) {
out.print(ansCharArray[i]);
}
out.println();
}
public static void prepare() throws Exception {
sc = new InputReader(System.in);
out = new OutputWriter(System.out);
}
public static void main(String[] args) throws Exception {
prepare();
int T = 1;
if(multiCase()) T = sc.nextInt();
while(T -- > 0) {
solve();
}
out.flush();
return ;
}
static class InputReader {
private final BufferedReader br;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public int nextInt() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
int x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public long nextLong() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
boolean negative = false;
if (c == '-') {
negative = true;
c = br.read();
}
long x = 0;
while (c > 32) {
x = x * 10 + c - '0';
c = br.read();
}
return negative ? -x : x;
}
public String next() throws IOException {
int c = br.read();
while (c <= 32) {
c = br.read();
}
StringBuilder sb = new StringBuilder();
while (c > 32) {
sb.append((char) c);
c = br.read();
}
return sb.toString();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
static class OutputWriter {
private final BufferedWriter writer;
public OutputWriter(OutputStream out) {
writer=new BufferedWriter(new OutputStreamWriter(out));
}
public void print(String str) {
try {
writer.write(str);
}
catch (IOException e) {
e.printStackTrace();
}
}
public void print(Object obj) {
print(String.valueOf(obj));
}
public void println(String str) {
print(str+"\n");
}
public void println() {
print('\n');
}
public void println(Object obj) {
println(String.valueOf(obj));
}
public void flush() {
try {
writer.flush();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 35d20fafce45a7ab6bcb72fc4187161e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static PrintWriter out = new PrintWriter(System.out);
static Scanner in = new Scanner(System.in);
static BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
//String[] strs = re.readLine().split(" "); int a = Integer.parseInt(strs[0]);
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
//String[] strs = re.readLine().split(" ");
//int T=Integer.parseInt(strs[0]);
int T=in.nextInt();
//nt T=1;
while(T>0){
//String[] strs1 = re.readLine().split(" ");
//int n=Integer.parseInt(strs1[0]);
//String s=re.readLine();
//char arr[]=s.toCharArray();
//Set<Integer>set=new HashSet<>();
//Map<Integer,Integer>map=new HashMap<>();
int n=in.nextInt();
String s=in.next();
char arr[]=s.toCharArray();
StringBuffer res=new StringBuffer();
for(int i=0;i<arr.length;i++){
if(i+2<arr.length&&arr[i+2]=='0'&& (i + 3 > n-1 || arr[i + 3] != '0')){
int sum=0;
for(int j=i;j<=i+2;j++)sum=sum*10+arr[j]-'0';
//out.println(sum);
//if(sum>260&&n-1-i-2!=2){
// int a=arr[i]-'0';a--;
// char b=(char)(a+'a');
// res.append(b);
// }
//else{
sum/=10;sum--;
char b=(char)(sum+'a');
res.append(b);
i+=2;
//}
}
else{
int a=arr[i]-'0';a--;
char b=(char)(a+'a');
res.append(b);
}
}
out.println(res.toString());
//out.println(Math.min(a,b));
T--;
}
out.flush();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 92ec13e84e996b721f817949424ca1e2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Hello {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t>0){
t--;
int n = in.nextInt();
String s = in.next();
StringBuilder ans = new StringBuilder();
int i = n-1;
while(i>=0){
int num = Integer.parseInt(s.charAt(i)+"");
if(num==0){
num = Integer.parseInt(s.substring(i-2,i)+"");
i = i-3;
}
else{
i--;
}
char c = (char)((int)'a'+num-1);
ans.append(c);
}
System.out.println(ans.reverse().toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0bce7cbb1a2f3964a6357f56c11abcaa | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
char[] chars={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
while(t-->0){
int n=sc.nextInt();
String s = sc.next();
String ans="";
int i=n-1;
while(i>=0){
char ch= s.charAt(i);
if(ch=='0'){
String temp=s.substring(i-2,i);
int idx=Integer.parseInt(temp);
ans=chars[idx-1]+ans;
i-=3;
}
else{
int c= ch+48;
char chv=(char)c;
ans=chv+ans;
i--;
}
}
System.out.println(ans);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 5e1b612a70a25f5d252691054e456d0a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class ssss {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
for(int i = 0; i < q; i++) {
int n = sc.nextInt();
int t = 0;
String s = sc.next();
String l = "";
for(int j = n - 1; j >= 0; j--){
if (s.charAt(j) == '0'){
t = Integer.parseInt(s.substring(j - 2, j));
l += (char) (t + 96);
j -= 2;
} else{
t = Integer.parseInt(String.valueOf(s.charAt(j)));
l += (char) (t + 96);
}
}
StringBuilder g = new StringBuilder(l);
g = g.reverse();
System.out.println(g);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0f5c188408c406c553e023da89e5fe0d | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long startTime = System.currentTimeMillis();
// for global initializations and methods starts here
// global initialisations and methods end here
static void run() {
boolean tc = true;
//AdityaFastIO r = new AdityaFastIO();
FastReader r = new FastReader();
try (OutputStream out = new BufferedOutputStream(System.out)) {
//long startTime = System.currentTimeMillis();
int testcases = tc ? r.ni() : 1;
int tcCounter = 1;
// Hold Here Sparky------------------->>>
// Solution Starts Here
start:
while (testcases-- > 0) {
int n = r.ni();
char[] s = r.word().toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
int curValue = s[i] - '0';
char cur = (char) (96 + curValue);
boolean charTwoPosAboveExists = i + 2 < n;
int twoPosAboveDigit = -1;
if (charTwoPosAboveExists) twoPosAboveDigit = s[i + 2] - '0';
boolean charThreePosAboveExists = i + 3 < n;
int threePosAboveDigit = -1;
if (charThreePosAboveExists) threePosAboveDigit = s[i + 3] - '0';
if (twoPosAboveDigit == 0) {
if (threePosAboveDigit == 0) {
sb.append(cur);
} else {
String firstTwoDigitChars = "" + curValue + "" + (s[i + 1] - '0');
int asciiValue = Integer.parseInt(firstTwoDigitChars) + 96;
cur = (char) asciiValue;
i += 2;
sb.append(cur);
}
} else sb.append(cur);
}
out.write((sb + "").getBytes());
out.write(("\n").getBytes());
}
// Solution Ends Here
} catch (IOException e) {
e.printStackTrace();
}
}
static class AdityaFastIO {
final private int BUFFER_SIZE = 1 << 16;
private final DataInputStream din;
private final byte[] buffer;
private int bufferPointer, bytesRead;
public BufferedReader br;
public StringTokenizer st;
public AdityaFastIO() {
br = new BufferedReader(new InputStreamReader(System.in));
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public AdityaFastIO(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public String readLine() throws IOException {
byte[] buf = new byte[100000001]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int ni() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public long nl() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg) return -ret;
return ret;
}
public double nd() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') c = read();
boolean neg = (c == '-');
if (neg) c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null) return;
din.close();
}
}
public static void main(String[] args) throws Exception {
run();
}
static int[] readIntArr(int n, AdityaFastIO r) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = r.ni();
return arr;
}
static long[] readLongArr(int n, AdityaFastIO r) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) arr[i] = r.nl();
return arr;
}
static List<Integer> readIntList(int n, AdityaFastIO r) throws IOException {
List<Integer> al = new ArrayList<>();
for (int i = 0; i < n; i++) al.add(r.ni());
return al;
}
static List<Long> readLongList(int n, AdityaFastIO r) throws IOException {
List<Long> al = new ArrayList<>();
for (int i = 0; i < n; i++) al.add(r.nl());
return al;
}
static long mod = 998244353;
static long modInv(long base, long e) {
long result = 1;
base %= mod;
while (e > 0) {
if ((e & 1) > 0) result = result * base % mod;
base = base * base % mod;
e >>= 1;
}
return result;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String word() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String line() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int ni() {
return Integer.parseInt(word());
}
long nl() {
return Long.parseLong(word());
}
double nd() {
return Double.parseDouble(word());
}
}
static int MOD = (int) (1e9 + 7);
static long powerLL(long x, long n) {
long result = 1;
while (n > 0) {
if (n % 2 == 1) result = result * x % MOD;
n = n / 2;
x = x * x % MOD;
}
return result;
}
static long powerStrings(int i1, int i2) {
String sa = String.valueOf(i1);
String sb = String.valueOf(i2);
long a = 0, b = 0;
for (int i = 0; i < sa.length(); i++) a = (a * 10 + (sa.charAt(i) - '0')) % MOD;
for (int i = 0; i < sb.length(); i++) b = (b * 10 + (sb.charAt(i) - '0')) % (MOD - 1);
return powerLL(a, b);
}
static long gcd(long a, long b) {
if (a == 0) return b;
else return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static long lower_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] >= x) r = m;
else l = m;
}
return r;
}
static int upper_bound(int[] arr, int x) {
int l = -1, r = arr.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (arr[m] <= x) l = m;
else r = m;
}
return l + 1;
}
static void addEdge(ArrayList<ArrayList<Integer>> graph, int edge1, int edge2) {
graph.get(edge1).add(edge2);
graph.get(edge2).add(edge1);
}
public static class Pair implements Comparable<Pair> {
int first;
int second;
public Pair(int first, int second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if (this.first != o.first)
return (int) (this.first - o.first);
else return (int) (this.second - o.second);
}
@Override
public int hashCode() {
int hash = 5;
hash = 17 * hash + this.first;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final Pair other = (Pair) obj;
return this.first == other.first;
}
}
public static class PairC<X, Y> implements Comparable<PairC> {
X first;
Y second;
public PairC(X first, Y second) {
this.first = first;
this.second = second;
}
public String toString() {
return "(" + first + "," + second + ")";
}
public int compareTo(PairC o) {
// TODO Auto-generated method stub
return o.compareTo((PairC) first);
}
}
static boolean isCollectionsSorted(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) <= list.get(i - 1)) return false;
return true;
}
static boolean isCollectionsSortedReverseOrder(List<Long> list) {
if (list.size() == 0 || list.size() == 1) return true;
for (int i = 1; i < list.size(); i++) if (list.get(i) >= list.get(i - 1)) return false;
return true;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 030626dceca840489c7433f40474c89f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String [] args)
{
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
String s = sc.next();
// String t1 = sc.nextLine();
String str[]=s.split("");
int a[]= new int[n];
for(int i =0;i<n;i++)
{
a[i]=Integer.parseInt(str[i]);
}
int ptr = n-1;
String res="";
while(ptr >=0)
{
if(a[ptr]!=0)
{
res=res+(char)(a[ptr]+96);
}
else{
if( !(ptr-2 <0) )
{
String temp = ""+a[ptr-2]+a[ptr-1];
ptr--;
ptr--;
// System.out.println(temp);
res=res+(char)(Integer.parseInt(temp)+96);
}
}
ptr--;
}
StringBuilder str1 = new StringBuilder(res);
System.out.println(str1.reverse().toString());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 8 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.