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 | d1deedca00d1be02489ed3a39fe8a691 | 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 Prog {
public static void main(String[] args) throws Exception {
//FileInputStream inputStream = new FileInputStream("input.txt");
//FileOutputStream outputStream = new FileOutputStream("output.txt");
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver(in, out);
for (int i = 0; i < args.length; i++)
out.println(args[i]);
int t = 1;
//t = in.nextInt();
while (t-- > 0)
solver.solve(1, in, out);
out.close();
}
static class Solver {
static InputReader in;
static PrintWriter out;
Solver(InputReader in, PrintWriter out) {
this.in = in;
this.out = out;
}
public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException, CloneNotSupportedException {
int q = in.nextInt();
while (q-- > 0) {
int n = in.nextInt();
char[] t = in.next().toCharArray();
String s = new String();
for (int i = t.length - 1; i >= 0; i--) {
char cnt;
if (t[i] == '0') {
String a = String.valueOf(t[i - 2]) + String.valueOf(t[i - 1]);
cnt = (char) (96 + Integer.parseInt(a));
i -= 2;
} else
cnt = (char) (96 + Integer.parseInt(String.valueOf(t[i])));
s = cnt + s;
}
out.println(s);
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(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 float nextFloat() {
return Float.parseFloat(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 17 | 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 | 100f7a7a93c77e5e7bef61f3f51b6f1e | 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 {
public static void main(String[] args) {
new Main().solve(new InputReader(System.in), new PrintWriter(System.out));
}
private void solve(InputReader in, PrintWriter pw) {
int t = in.nextInt();
for (; t > 0; t--) {
int n = in.nextInt();
String s = in.next();
StringBuilder sb = new StringBuilder();
for (int i = n - 1; i >= 0; i--) {
if (s.charAt(i) == '0') {
int u = Integer.parseInt(s.substring(i - 2, i));
sb.append((char) ('a' + u - 1));
i -= 2;
} else {
sb.append((char) ('a' + s.charAt(i) - '1'));
}
}
pw.println(sb.reverse());
}
pw.close();
}
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(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 String nextLine() {
String str;
try {
str = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return str;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextArray(int n, int begin) {
int[] ans = new int[n + begin];
for (int i = begin; i < n + begin; i++) {
ans[i] = nextInt();
}
return 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 17 | 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 | e5a3b2685bb6292d5a203153c973cbc7 | 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 | // B. Decode String
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int numTimes = scanner.nextInt();
// Will contain Lists of Strings s
List<String> array = new ArrayList<>();
// Input
scanner.nextLine();
for (int i = 0; i < numTimes; i++) {
scanner.nextInt(); // size
String s = scanner.next();
array.add(s);
}
// Output
for (int i = 0; i < numTimes; i++) {
System.out.println(getDecoded(array.get(i)));
}
}
static String getDecoded(String s){
String encodedStr = "";
for (int i = s.length()-1; i >= 0; i--) {
if (s.charAt(i) == '0') {
String number = "";
number += s.charAt(i-2);
number += s.charAt(i-1);
char ltr = (char)(Integer.parseInt(number) + 96);
encodedStr = ltr + encodedStr;
i -= 2;
} else {
Character ch = s.charAt(i);
char ltr = (char)(Character.getNumericValue(ch) + 96);
encodedStr = ltr + encodedStr;
}
}
return encodedStr;
}
} | 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 17 | 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 | a9e3e277d170c352d4fa071481e52047 | 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.*;
public class P1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0) {
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
char c [] = new char[26];
for(char i = 'a' ;i<='z';i++) {
c[i - 'a'] = i;
}
int i = 0;
StringBuilder ans = new StringBuilder();
while(i<n) {
if(i + 3 <n && s.charAt(i + 2) == '0' && s.charAt(i + 3) == '0') {
int k = s.charAt(i) - '0';
ans.append(c[k-1]);
i++;
}
if(i + 2 < n && s.charAt(i+2) == '0' ) {
int k = (s.charAt(i) - '0' ) * 10;
k+=(s.charAt(i + 1) - '0');
ans.append(c[k-1]);
i = i+3;
}else {
int k = s.charAt(i) - '0';
ans.append(c[k-1]);
i++;
}
}
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 17 | 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 | 1c16f5048751c4a68907bd28f5297c7e | 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.Arrays;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
while(q-- != 0) {
char ch = 'a';
char[] arrch = new char[26];
arrch[0] = ch;
for(int i =1 ; i < 26 ; i++)
arrch[i]= ++ch;
int n = in.nextInt();
String t = in.next();
String s = "";
int index = 0;
for(int i = t.length() -1 ; i >= 0 ; i--) {
if(t.charAt(i) != '0') {
index = Integer.parseInt(t.charAt(i)+"");
index--;
}else {
index = Integer.parseInt(t.charAt(i-2)+""+t.charAt(i-1));
index--;
i -=2;
}
s += arrch[index];
}
String ss = "";
for(int i = s.length()-1; i >= 0 ; i--)
ss += s.charAt(i);
System.out.println(ss );
}
}
} | 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 17 | 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 | b384c9d4f929b748e9c7489fe198b347 | 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 hello {
public static void main(String[] args){
Scanner innn = new Scanner(System.in);
int n = innn.nextInt();
int k = 0;
int nn = 0;
String ans = "";
String s = "";
for(int j = 0; j < n; j++){
ans = "";
nn = innn.nextInt();
s = innn.next();
for(int i = s.length() - 1; i >= 0; i--) {
if (s.charAt(i) != '0'){
k = 96 + Character.getNumericValue(s.charAt(i));
}else if (s.charAt(i) == '0'){
k = 96 + (Character.getNumericValue(s.charAt(i - 2)) * 10 + Character.getNumericValue(s.charAt(i - 1)));
i = i - 2;
}
ans = (char)k + 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 17 | 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 | 8c67c214f85fb609c1986639c220d4e6 | 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 App {
public static void main(String[] args) {
Map<Integer, Character> map = new HashMap<>();
for (char c = 'a'; c <= 'z'; c++) {
map.put(c - 'a' + 1, c);
}
Scanner scanner = new Scanner(System.in);
int q = scanner.nextInt();
while (q-- > 0) {
int len = scanner.nextInt();
scanner.nextLine();
String input = scanner.nextLine();
StringBuilder sb = new StringBuilder();
char[] chars = input.toCharArray();
int buffer = 0;
for (int i = 0; i < chars.length; i++) {
int num1 = chars[i] - '0';
int num2 = -1;
int num3 = -1;
int totalNum = num1;
if (i + 2 < chars.length) {
num2 = chars[i + 1] - '0';
num3 = chars[i + 2] - '0';
}
if (num3 == 0 && (i + 3 >= chars.length || chars[i + 3] != '0')) {
totalNum = 10 * num1 + num2;
i += 2;
}
if (i + 1 < chars.length && chars[i + 1] == '0'){
totalNum = num1 * 10 + chars[i + 1] - '0';
i++;
}
char c = map.get(totalNum);
sb.append(c);
}
System.out.println(sb);
}
scanner.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 17 | 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 | 019b8550bcf55fa9a30030324a65bc58 | 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 {
// 9:30
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
StringBuilder sb = new StringBuilder("");
int i=0;
while(i<n){
if(i+2<n && s.charAt(i+2)=='0' && (i+3>=n || ((i+3<n)&&(s.charAt(i+3)!='0')))){
char c = (char)('a'+(Integer.parseInt(s.substring(i,i+2))-1));
sb.append(c);
i+=2;
}else{
char c = (char)('a'+(Integer.parseInt(s.charAt(i)+"")-1));
sb.append(c);
}
i++;
}
System.out.println(sb.toString());
}
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 17 | 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 | 9ebe5af4e1580f07e48fbdb02ff738a7 | 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 KMPAlgorithm {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
char[] reference="1abcdefghijklmnopqrstuvwxyz".toCharArray();
while(T>0) {
int n=sc.nextInt();
String coded = sc.next();
StringBuilder message = new StringBuilder();
for(int j=n-1;j>-1;j--) {
if (coded.charAt(j) != '0') {
int index = Integer.parseInt(String.valueOf(coded.charAt(j)));
message.append(reference[index]);
} else {
char newFirst = coded.charAt(j - 2);
char second = coded.charAt(j - 1);
int newIndex = Integer.parseInt(String.valueOf(newFirst)) * 10 + Integer.parseInt(String.valueOf(second));
message.append(reference[newIndex]);
j = j - 2;
}
}
String newMessage = message.reverse().toString();
System.out.println(newMessage);
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 17 | 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 | 4186049770cb5060bbbab85c1710ec08 | 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 {
static Scanner scr = new Scanner(System.in);
static int length;
public static void main(String[] args) {
int iterations = Integer.parseInt(scr.nextLine());
for(int i = 0; i < iterations; i++)
{
length = Integer.parseInt(scr.nextLine());
System.out.println(decode(split(convertToInt(scr.nextLine().toCharArray()))));
}
}
static String decode(int[] arr)
{
StringBuilder str = new StringBuilder();
for(int i : arr)
{
if(i != 0)
str.append((char) ((int) 'a' - 1 + i));
}
return str.toString();
}
static int[] splitCopy(int[] arr)
{
int[] tab = new int[arr.length];
for(int i = 0; i < arr.length; i++)
{
if(arr[i] != 0)
try {
if(arr[i+2] == 0)
{
tab[i] = arr[i]*10 + arr[i+1];
}
else tab[i] = arr[i];
}catch (ArrayIndexOutOfBoundsException e)
{
tab[i] = arr[i];
}
}
return tab;
}
static int[] split(int[] arr)
{
boolean continueFlag = false;
int[] tab = new int[arr.length];
for(int i = 0; i < arr.length; i++)
{
if(continueFlag)
{
continueFlag = false;
continue;
}
if(arr[i] != 0)
try {
if(arr[i+2] == 0)
{
try {
if(arr[i+3] != 0) {
tab[i] = arr[i] * 10 + arr[i + 1];
continueFlag = true;
}
else tab[i] = arr[i];
}catch (ArrayIndexOutOfBoundsException e)
{
tab[i] = arr[i]*10 + arr[i+1];
continueFlag = true;
}
}
else tab[i] = arr[i];
}catch (ArrayIndexOutOfBoundsException e)
{
tab[i] = arr[i];
}
}
return tab;
}
static int[] convertToInt(char[] arr)
{
int[] tab = new int[arr.length];
for(int i = 0; i < arr.length; i++)
{
tab[i] = arr[i] - 48;
}
return tab;
}
}
| 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 17 | 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 | dd6df2aab7f28d513bbe52387c74142d | 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 Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int cases = sc.nextInt();
for(int i =0;i<cases;i++){
int letters = sc.nextInt();
String s = sc.next();
String sol = solution(s);
System.out.println(sol);
}
}
public static String solution(String s){
if(s.length()==0)
return "";
if(s.charAt(s.length()-1) == '0'){
char temp =(char) (Integer.parseInt(s.substring(s.length()-3,s.length()-1))+96);
return solution(s.substring(0,s.length()-3)) + temp;
}else{
char temp =(char) (Integer.parseInt(s.substring(s.length()-1))+96);
return solution(s.substring(0,s.length()-1)) + temp;
}
}
}
| 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 17 | 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 | e7598c5b98ee0bd65cef8e3419bd721a | 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 final class Code
{
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[] parent = new int[100000];
static int[] rank = new int[100000];
static void makeset()
{
for (int i = 1; i < 100000; i++)
{
parent[i] = i;
rank[i] = 0;
}
}
//Uses path compression
static int findpar(int node)
{
if (node == parent[node]) return node;
return parent[node] = findpar(parent[node]);
}
//Uses union by rank
static void union(int u, int v)
{
u = findpar(u);
v = findpar(v);
if (rank[u] < rank[v]) parent[u] = v;
if (rank[u] > rank[v]) parent[v] = u;
else
{
parent[v] = u;
rank[u]++;
}
}
static boolean areConnected(int a, int b)
{
return findpar(a) == findpar(b);
}
static int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a % b);
}
static int lcm(int a, int b)
{
return a * b / gcd(a, b);
}
static boolean isPrime(int n)
{
// Check if n=1 or n=0
if (n <= 1)
return false;
// Check if n=2 or n=3
if (n == 2 || n == 3)
return true;
// Check whether n is divisible by 2 or 3
if (n % 2 == 0 || n % 3 == 0)
return false;
// Check from 5 to square root of n
// Iterate i by (i+6)
for (int i = 5; i <= Math.sqrt(n); i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static int hsb(int x)
{
return (int) (Math.log(x) / Math.log(2));
}
public static void main(String[] args)
{
try
{
FastReader y = new FastReader();
int t = y.nextInt();
while (t-- > 0)
{
StringBuilder st=new StringBuilder();
int n=y.nextInt();
String s=y.nextLine();
for(int i=n-1;i>=0;i--)
{
char ch=s.charAt(i);
int ch1= ch-'0';
if(ch!='0')
st=st.append((char) (97+ch1-1));
else
{
int a=s.charAt(i-1)-'0';
int b=s.charAt(i-2)-'0';
int x=b*10+a;
st=st.append((char)(97+x-1));
i-=2;
}
//System.out.println(st);
}
System.out.println(st.reverse());
}
} catch (Exception 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 17 | 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 | 9004242af9189142d2cffe82ea2f9c62 | 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 B_Decode_String {
final int mod = 1000000007;
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 void swap(long[] a, int i, int j) {
long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader t = new FastReader();
PrintWriter o = new PrintWriter(System.out);
int test = t.nextInt();
while (test-- > 0) {
long min = Integer.MIN_VALUE, max = Integer.MAX_VALUE;
//long ans =0 ;
long n = t.nextLong();
String s = t.next();
char[] c = s.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i=0; i<n; i++) {
if (i<n-2) {
String h = s.substring(i, i+2);
int j = Integer.parseInt(h);
if (c[i+2] == '0' && j<27 && (i+3>=n || c[i+3]!='0')) {
sb.append((char)('a'+j-1));
i+=2;
}
else {
sb.append((char)('a'+(c[i]-'0'-1)));
}
}
else {
sb.append((char)('a'+(c[i]-'0'-1)));
}
}
o.println(sb.toString());
// long m = t.nextLong();
// ArrayList<Integer> al = new ArrayList<>();
// HashSet<Integer> set = new HashSet<>();
// HashMap<Integer, Integer> map = new HashMap<>();
// TreeMap<Integer, Integer> map = new TreeMap<>();
// for (int i = 0; i < n; ++i) {
// for (int j = 0; j < n; ++j) {
// }
// }
}
o.flush();
o.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 17 | 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 | 960e66f08ce9dba7cfe34146d8dbea4d | 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.*;
public class Main{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-- > 0){
int n = Integer.parseInt(br.readLine());
char[] s = br.readLine().toCharArray();
int i = s.length-1;
StringBuffer ans = new StringBuffer("");
while(i >= 0){
if(s[i] == '0'){
int val = Integer.parseInt(s[i-2]+""+s[i-1]);
ans.insert(0,(char)('a'+(val-1)));
i -= 3;
}else{
int val = Integer.parseInt(s[i]+"");
ans.insert(0,(char)('a'+(val-1)));
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 17 | 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 | 0859170998bee9583548a952c7f5adac | 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 sc = new Scanner(System.in);
int q = sc.nextInt();
for (int tc = 0; tc < q; ++tc) {
sc.nextInt();
String t = sc.next();
System.out.println(solve(t));
}
sc.close();
}
static String solve(String t) {
StringBuilder reversed = new StringBuilder();
int index = t.length() - 1;
while (index != -1) {
if (t.charAt(index) == '0') {
reversed.append(
(char) (10 * (t.charAt(index - 2) - '0') + (t.charAt(index - 1) - '0') - 1 + 'a'));
index -= 3;
} else {
reversed.append((char) ((t.charAt(index) - '0') - 1 + 'a'));
--index;
}
}
return reversed.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 17 | 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 | 1c7ce677022a81c603ce3d6aad1566fc | 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 code {
public static void main (String[] args) throws java.lang.Exception {
Scanner sn = new Scanner(System.in);
int tc = sn.nextInt();
while (tc-- > 0) {
int l = sn.nextInt();
String str = sn.next();
String ans = "";
for (int i = str.length()-1 ; i >= 0 ; i--) {
char ch = str.charAt(i);
int v = (ch - '0');
if (v == 0) {
ans = (char)(Integer.parseInt(str.substring(i - 2 , i)) + 'a' - 1) + ans;
i-=2;
} else {
ans = (char) (v + 'a' - 1) + 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 17 | 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 | 2f9f208479de77970e3726ff1868e102 | 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.lang.*;
public class DecodeString {
public static void main(String[] args) throws IOException{
FastReader s = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = s.nextInt();
while(t-->0){
int n = s.nextInt();
char[] ch = s.next().toCharArray();
StringBuilder sb = new StringBuilder();
for(int i = ch.length - 1; i >= 0; i--){
int val = 0;
if(ch[i] == '0'){
val += Integer.parseInt("" + ch[i - 2] + ch[i - 1]);
i -= 2;
}
else{
val += ch[i] - '0';
}
sb.insert(0, (char)(val + 'a' - 1));
}
out.println(sb);
}
out.flush();
}
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
String nextLine() throws IOException {
String str = "";
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
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 17 | 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 | 1cf31d74ae5967c38cd78191b1fd9287 | 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 scanner = new Scanner(System.in);
int t = scanner.nextInt();
while(t-- > 0) {
int n = scanner.nextInt();
String s = scanner.next();
// System.out.println(s);
StringBuilder res = new StringBuilder();
for(int i = n - 1;i >= 0;i--) {
char ch = s.charAt(i);
if(ch > '0') {
res.append((char) (Integer.parseInt(String.valueOf(ch)) + 'a' - 1));
}
else {
res.append((char) (Integer.parseInt(s.substring(i - 2, i)) + 'a' - 1));
i -= 2;
}
}
System.out.println(res.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 17 | 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 | 139f6c217745eb598a886ca4a85f16a6 | 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.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class Solution
{
public static class CFScanner
{
BufferedReader br;
StringTokenizer st;
public CFScanner()
{
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 void main(String[] args)
{
// int n = in.nextInt();
// long n = in.nextLong();
// double n = in.nextDouble();
// String s = in.next();
CFScanner in = new CFScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int T = in.nextInt();
for (int t = 1; t <= T; t++)
{
int n = in.nextInt();
String s = in.next();
out.println(getStr(s));
}
out.close();
}
private static String getStr(String s)
{
StringBuilder strBd = new StringBuilder();
Set<Integer> zeros = new HashSet<>();
for (int i = 0; i < s.length(); i++)
{
if (s.charAt(i) == '0')
{
if (i + 1 < s.length() && s.charAt(i + 1) == '0')
{
continue;
}
zeros.add(i);
}
}
for (int i = 0; i < s.length(); i++)
{
if (zeros.contains(i))
{
continue;
}
else if (zeros.contains(i + 2))
{
String sub = s.charAt(i) + "" + s.charAt(i + 1);
int val = Integer.valueOf(sub);
strBd.append((char)('a' + --val));
i += 2;
}
else
{
String sub = s.charAt(i) + "";
int val = Integer.valueOf(sub);
strBd.append((char)('a' + --val));
}
}
return strBd.toString();
}
private static int getEle(int a, int b, int c)
{
int first = Math.abs(a - 1);
int second = Math.abs(c - 1) + Math.abs(c - b);
if (first == second)
{
return 3;
}
return first < second ? 1 : 2;
}
} | 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 17 | 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 | dd5834e82783890dec7cfea45c63aadc | 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 static java.lang.Integer.parseInt;
public class Problem1729B {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int q = parseInt(scanner.nextLine()); // number of queries
// for each query
for (int i = 0; i < q; i++) {
int n = parseInt(scanner.nextLine()); // get the number of characters in query
int removals = 0; // count characters decoded
String t = scanner.nextLine(); // get the query
String out = "";
while (removals < n) {
int charCode;
if (t.charAt(t.length() - 1) == '0') {
charCode = Integer.parseInt(t.substring(t.length() - 3, t.length() - 1));
t = t.substring(0, t.length() - 3); // remove the last 3 characters
removals += 3; // increment the number of characters decoded
} else {
charCode = parseInt(t.substring(t.length() - 1)); // get the last character
t = t.substring(0, t.length() - 1); // remove the last character
removals += 1; // increment the number of characters decoded
}
out += (char) (charCode + 96); // convert the character code to a character and add it to the output
}
System.out.println(new StringBuilder(out).reverse()); // print the 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 17 | 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 | 2b3742c7ed43a00727e59d6cb42658d6 | 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.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-- > 0){
int len = scn.nextInt();
scn.nextLine();
String s = scn.nextLine();
StringBuilder sb = new StringBuilder();
int n = s.length();
for(int i=0; i<n; i++){
if(i+2 < n && s.charAt(i+2) == '0'){
if(i+3<n && s.charAt(i+3) == '0'){
sb.append((char)(s.charAt(i)-'0'+'a'-1));
}else{
String ss = s.substring(i, i+2);
int num = Integer.parseInt(ss);
sb.append((char)('a'+num-1));
i+=2;
}
}
else{
sb.append((char)(s.charAt(i)-'0'+'a'-1));
}
}
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 17 | 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 | 82837c734bdbbef0a25f84edcab40de1 | 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 Codechef
{
static void solve(){
Scanner sc =new Scanner(System.in);
int p=sc.nextInt();
int q=sc.nextInt();
int r=sc.nextInt();
int count=0;
for(int i=0;i<31;i++){
int val=(int)Math.pow(2, i);
// System.out.println(val);
if(((p|q|r)&val)==0)
{
// System.out.println("something");
continue;}
if((p&val)==val&&(q&val)==0&&(r&val)==0)
{System.out.println("0");return ;}
else if((p&val)==0&&(q&val)==val&&(r&val)==0)
{System.out.println("0");return ;}
else if((p&val)==0&&(q&val)==0&&(r&val)==val)
{System.out.println("0");return ;}
else if((p&val&q&r)==val)
count++;
}
System.out.println((int)Math.pow(4, count));
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc =new Scanner(System.in);
int n1=sc.nextInt();
while(n1-->0){
int l=sc.nextInt();
String s=sc.next();
String fin="";
int i=s.length()-1;
while(i>=0){
if(s.charAt(i)=='0'){
i=i-2;
int n=Integer.parseInt( s.substring(i, i+2));
fin=(char)(n+96)+fin;
i-=1;
}
else{
int n=Integer.parseInt( s.substring(i, i+1));
i=i-1;
fin=(char)(n+96)+fin;
}
// System.out.println(fin);
}
System.out.println(fin);
}
}
}
| 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 17 | 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 | 457249e5a03f787c5d193734971634b6 | 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.lang.*;
public class MyClass
{
public static void main(String args[])throws IOException
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
String s=sc.next();
int i=n-1;
String ans="";
while(i>=0)
{
if(s.charAt(i)=='0')
{
char ch1=s.charAt(i-2);
char ch2=s.charAt(i-1);
int ss=((Integer.parseInt(String.valueOf(ch1)))*10)+(Integer.parseInt(String.valueOf(ch2)));
//int ss=((int)(s.charAt(i-2))*10)+(int)s.charAt(i-1);
//System.out.print(ss+" ");
//cout<<char(97+ss)<<" ";
ans=ans+(char)(96+ss);
i=i-3;
}
else
{
char ch = s.charAt(i);
int ss = Integer.parseInt(String.valueOf(ch));
//System.out.print(ss+" ");
//cout<<char(97+ss)<<" ";
ans=ans+(char)(96+ss);
i--;
}
}
String fin="";
int l=ans.length();
for(int j=l-1;j>=0;j--)
{
fin+=(ans.charAt(j));
}
System.out.println(fin);
}
}
} | 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 17 | 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 | 810e1c3dbd0108306d8a7f743c8a4090 | 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);
char[] temp=new char[26];
char ch=97;
for(int i=0;i<26;i++){
temp[i]=ch;
ch++;
}
int n=sc.nextInt();
for(int j=0;j<n;j++){
int m=sc.nextInt();
String s=sc.next();
String rs="";
for(int i=0;i<m;i++){
if(i+3<m && s.charAt(i+3)=='0' && s.charAt(i+2)=='0'){
rs+=temp[(s.charAt(i)-'0')-1];
i++;
String str=String.valueOf(s.charAt(i))+String.valueOf(s.charAt(i+1));
int x=Integer.valueOf(str);
rs+=temp[x-1];
i++;
i++;
continue;
}
if(i+2<m && s.charAt(i+2)=='0'){
String str=String.valueOf(s.charAt(i))+String.valueOf(s.charAt(i+1));
int x=Integer.valueOf(str);
rs+=temp[x-1];
i++;
i++;
continue;
}
rs+=temp[(s.charAt(i)-'0')-1];
}
System.out.println(rs);
}
}
} | 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 17 | 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 | 5b40fa0c33cd4074d3499407733f5959 | 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 practice;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class cp
{
public static void main(String[] args) throws IOException
{
//Your Solve
// Reader s = new Reader();
FastReader s = new FastReader();
// Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int p = 0;p < t;p++) {
int n = s.nextInt();
String str = s.next();
ArrayList<Character> ans = new ArrayList<>();
for(int i = n-1;i >= 0;i--) {
if(str.charAt(i)=='0') {
ans.add((char)(Integer.parseInt(str.substring(i-2,i))+'a'-1));
i -= 2;
}else {
ans.add((char)(Integer.parseInt(str.substring(i,i+1)) + 'a'-1));
}
}
// Stack<Integer> ans = new Stack<>();
//
// for(int i = n-1;i >= 0;i--) {
// if(str.charAt(i)=='0') {
// ans.add((str.charAt(i-2)-'0')*10 + str.charAt(i-1)-'0');
// i -= 2;
// }else {
// ans.add(str.charAt(i) - '0');
// }
// }
StringBuilder out = new StringBuilder();
for(int i = ans.size()-1;i>=0;i--) {
out.append(ans.get(i));
// System.out.print((char)(ans.get(i)+'a'-1));
// System.out.flush();
}
System.out.println(out);
}
}
public static int multiplicativeModInverse(long a,int m) {
//works only if m prime
if(gcd(a,m)!=1) {
return -1;//ans does not exist
}
//ans = a^(m-2)%m
return power(a,m-2,m);
}
public static int binaryExpo(int a,int b,int m) {
if(b==0) {
return 1;
}
if(b==1) {
return a;
}
long smallAns = binaryExpo(a, b/2, m);
if(b%2==0) {
return Math.floorMod(smallAns*smallAns,m);
}else {
return Math.floorMod(smallAns*smallAns*a, m);
}
}
public static int divModulo(long a,long b,int m) {
//find (a/b) mod m = a* b^-1 mod m
//works only if m prime
long A = a;
long Binverse = multiplicativeModInverse(b, m);
return Math.floorMod(A*Binverse,m);
}
public static long gcd(long a,long b) {
if(b>a) {
long temp = a;
a = b;
b = temp;
}
while(b>0) {
long temp = a;
a = b;
b = temp%b;
}
return a;
}
public static Vector<Integer> sieveOfEratosthenes(int n)
{
// Create a boolean array
// "prime[0..n]" and
// initialize all entries
// it as true. A value in
// prime[i] will finally be
// false if i is Not a
// prime, else true.
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
// If prime[p] is not changed, then it is a
// prime
if (prime[p] == true && (long)p*p <= n)
{
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
Vector<Integer> v = new Vector<>();
// Print all prime numbers
for (int i = 2; i <= n; i++)
{
if (prime[i] == true)
v.add(i);
}
return v;
}
public static int logbase2(long n) {
int count = 0;
if(n==0) {
return -1;
}
while(n >= 2) {
n /= 2;
count++;
}
return count;
}
public static boolean isPrime(int n)
{
// Corner cases
if (n <= 1) return false;
if (n <= 3) return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n%2 == 0 || n%3 == 0) return false;
for (int i=5; i*i<=n; i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return false;
return true;
}
static long binomialCoeff(long n, long k)
{
long res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (int i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
public static void shuffleArray(int[] ar)
{
// If running on Java 6 or older, use `new Random()` on RHS here
Random rnd = new Random();
for (int i = ar.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
}
/* Iterative Function to calculate (x^y) in O(log y) */
static int power(long a, long b, int m)
{
int res = 1; // Initialize result
long x = a;
long y = b;
x = x % m; // Update x if it is more than or
// equal to m
if (x == 0)
return 0; // In case x is divisible by m;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = (int)((res * x) % m);
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % m;
}
return res;
}
static long getPairsCount(int n, long sum,long arr[])
{
HashMap<Long, Integer> hm = new HashMap<>();
// Store counts of all elements in map hm
for (int i = 0; i < n; i++) {
// initializing value to 0, if key not found
if (!hm.containsKey(arr[i]))
hm.put(arr[i], 0);
hm.put(arr[i], hm.get(arr[i]) + 1);
}
long twice_count = 0;
// iterate through each element and increment the
// count (Notice that every pair is counted twice)
for (int i = 0; i < n; i++) {
if (hm.get(sum - arr[i]) != null)
twice_count += hm.get(sum - arr[i]);
// if (arr[i], arr[i]) pair satisfies the
// condition, then we need to ensure that the
// count is decreased by one such that the
// (arr[i], arr[i]) pair is not considered
if (sum - arr[i] == arr[i])
twice_count--;
}
// return the half of twice_count
return twice_count / 2;
}
public static<T,V> HashMap<T,V>
sortByValue(HashMap<T,V> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<T,V> > list
= new LinkedList<Map.Entry<T,V> >(
hm.entrySet());
// Sort the list using lambda expression
Collections.sort(
list,
(i1,
i2) -> ((String) i1.getValue()).compareTo((String) i2.getValue()));
// put data from sorted list to hashmap
HashMap<T,V> temp
= new LinkedHashMap<T,V>();
for (Map.Entry<T,V> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
public static<T> HashMap<T,Integer>
sortByValueDescending(HashMap<T,Integer> unSortedMap)
{
LinkedHashMap<T,Integer> reverseSortedMap = new LinkedHashMap<>();
unSortedMap.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.forEachOrdered(x -> reverseSortedMap.put(x.getKey(), x.getValue()));
return reverseSortedMap;
}
static int lower_bound(long array[], long key,long start,long end)
{
// Initialize starting index and
// ending index
long low = start, high = end;
long mid;
// Till high does not crosses low
while (low < high) {
// Find the index of the middle element
mid = low + (high - low) / 2;
// If key is less than or equal
// to array[mid], then find in
// left subarray
if (key <= array[(int)mid]) {
high = mid;
}
// If key is greater than array[mid],
// then find in right subarray
else {
low = mid + 1;
}
}
// If key is greater than last element which is
// array[n-1] then lower bound
// does not exists in the array
if (low < end && array[(int)low] < key) {
low++;
}
// Returning the lower_bound index
return (int)low;
}
static int upper_bound(long array[], long key,long start,long end)
{
// Initialize starting index and
// ending index
long low = start, high = end;
long mid;
// Till high does not crosses low
while (low < high) {
// Find the index of the middle element
mid = low + (high - low) / 2;
// If key is less than or equal
// to array[mid], then find in
// left subarray
if (key >= array[(int)mid]) {
low = mid+1;
}
// If key is greater than array[mid],
// then find in right subarray
else {
high = mid;
}
}
// If key is greater than last element which is
// array[n-1] then lower bound
// does not exists in the array
if (low < end && array[(int)low] <= key) {
low++;
}
// Returning the lower_bound index
return (int)low;
}
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 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();
}
}
}
class Pair implements Comparable<Pair>{
int lastOcc;
char ch;
public Pair(int lastOcc,char ch) {
this.lastOcc = lastOcc;
this.ch = ch;
}
public int compareTo(Pair p) {
return (this.lastOcc<p.lastOcc)?-1:1;
}
}
//class Pair implements Comparator<Pair>{
// int lastOcc;
// char ch;
// public Pair(int lastOcc,char ch) {
// this.lastOcc = lastOcc;
// this.ch = ch;
// }
//
//// static class PairComparator implements Comparator<Pair>{
// public int compare(Pair p1,Pair p2) {
// return (p1.lastOcc < p2.lastOcc) ? -1 : 1;
// }
//
//// }
//
//}
class Domino{
int a,b;
boolean visited;
public Domino(int a,int b) {
this.a = a;
this.b = b;
visited = 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 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 | 46a07def3bd314eb747c687478eeab03 | 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 practice;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class cp
{
public static void main(String[] args) throws IOException
{
//Your Solve
// Reader s = new Reader();
FastReader s = new FastReader();
// Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int p = 0;p < t;p++) {
int n = s.nextInt();
String str = s.next();
Stack<Integer> ans = new Stack<>();
for(int i = n-1;i >= 0;i--) {
if(str.charAt(i)=='0') {
ans.add((str.charAt(i-2)-'0')*10 + str.charAt(i-1)-'0');
i -= 2;
}else {
ans.add(str.charAt(i) - '0');
}
}
StringBuilder out = new StringBuilder();
while(!ans.isEmpty()) {
out.append((char)(ans.pop()+'a'-1));
}
System.out.println(out);
}
}
public static int multiplicativeModInverse(long a,int m) {
//works only if m prime
if(gcd(a,m)!=1) {
return -1;//ans does not exist
}
//ans = a^(m-2)%m
return power(a,m-2,m);
}
public static int binaryExpo(int a,int b,int m) {
if(b==0) {
return 1;
}
if(b==1) {
return a;
}
long smallAns = binaryExpo(a, b/2, m);
if(b%2==0) {
return Math.floorMod(smallAns*smallAns,m);
}else {
return Math.floorMod(smallAns*smallAns*a, m);
}
}
public static int divModulo(long a,long b,int m) {
//find (a/b) mod m = a* b^-1 mod m
//works only if m prime
long A = a;
long Binverse = multiplicativeModInverse(b, m);
return Math.floorMod(A*Binverse,m);
}
public static long gcd(long a,long b) {
if(b>a) {
long temp = a;
a = b;
b = temp;
}
while(b>0) {
long temp = a;
a = b;
b = temp%b;
}
return a;
}
public static Vector<Integer> sieveOfEratosthenes(int n)
{
// Create a boolean array
// "prime[0..n]" and
// initialize all entries
// it as true. A value in
// prime[i] will finally be
// false if i is Not a
// prime, else true.
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
// If prime[p] is not changed, then it is a
// prime
if (prime[p] == true && (long)p*p <= n)
{
// Update all multiples of p
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
Vector<Integer> v = new Vector<>();
// Print all prime numbers
for (int i = 2; i <= n; i++)
{
if (prime[i] == true)
v.add(i);
}
return v;
}
public static int logbase2(long n) {
int count = 0;
if(n==0) {
return -1;
}
while(n >= 2) {
n /= 2;
count++;
}
return count;
}
public static boolean isPrime(int n)
{
// Corner cases
if (n <= 1) return false;
if (n <= 3) return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n%2 == 0 || n%3 == 0) return false;
for (int i=5; i*i<=n; i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return false;
return true;
}
static long binomialCoeff(long n, long k)
{
long res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (int i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
public static void shuffleArray(int[] ar)
{
// If running on Java 6 or older, use `new Random()` on RHS here
Random rnd = new Random();
for (int i = ar.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
}
/* Iterative Function to calculate (x^y) in O(log y) */
static int power(long a, long b, int m)
{
int res = 1; // Initialize result
long x = a;
long y = b;
x = x % m; // Update x if it is more than or
// equal to m
if (x == 0)
return 0; // In case x is divisible by m;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = (int)((res * x) % m);
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % m;
}
return res;
}
static long getPairsCount(int n, long sum,long arr[])
{
HashMap<Long, Integer> hm = new HashMap<>();
// Store counts of all elements in map hm
for (int i = 0; i < n; i++) {
// initializing value to 0, if key not found
if (!hm.containsKey(arr[i]))
hm.put(arr[i], 0);
hm.put(arr[i], hm.get(arr[i]) + 1);
}
long twice_count = 0;
// iterate through each element and increment the
// count (Notice that every pair is counted twice)
for (int i = 0; i < n; i++) {
if (hm.get(sum - arr[i]) != null)
twice_count += hm.get(sum - arr[i]);
// if (arr[i], arr[i]) pair satisfies the
// condition, then we need to ensure that the
// count is decreased by one such that the
// (arr[i], arr[i]) pair is not considered
if (sum - arr[i] == arr[i])
twice_count--;
}
// return the half of twice_count
return twice_count / 2;
}
public static<T,V> HashMap<T,V>
sortByValue(HashMap<T,V> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<T,V> > list
= new LinkedList<Map.Entry<T,V> >(
hm.entrySet());
// Sort the list using lambda expression
Collections.sort(
list,
(i1,
i2) -> ((String) i1.getValue()).compareTo((String) i2.getValue()));
// put data from sorted list to hashmap
HashMap<T,V> temp
= new LinkedHashMap<T,V>();
for (Map.Entry<T,V> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
public static<T> HashMap<T,Integer>
sortByValueDescending(HashMap<T,Integer> unSortedMap)
{
LinkedHashMap<T,Integer> reverseSortedMap = new LinkedHashMap<>();
unSortedMap.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.forEachOrdered(x -> reverseSortedMap.put(x.getKey(), x.getValue()));
return reverseSortedMap;
}
static int lower_bound(long array[], long key,long start,long end)
{
// Initialize starting index and
// ending index
long low = start, high = end;
long mid;
// Till high does not crosses low
while (low < high) {
// Find the index of the middle element
mid = low + (high - low) / 2;
// If key is less than or equal
// to array[mid], then find in
// left subarray
if (key <= array[(int)mid]) {
high = mid;
}
// If key is greater than array[mid],
// then find in right subarray
else {
low = mid + 1;
}
}
// If key is greater than last element which is
// array[n-1] then lower bound
// does not exists in the array
if (low < end && array[(int)low] < key) {
low++;
}
// Returning the lower_bound index
return (int)low;
}
static int upper_bound(long array[], long key,long start,long end)
{
// Initialize starting index and
// ending index
long low = start, high = end;
long mid;
// Till high does not crosses low
while (low < high) {
// Find the index of the middle element
mid = low + (high - low) / 2;
// If key is less than or equal
// to array[mid], then find in
// left subarray
if (key >= array[(int)mid]) {
low = mid+1;
}
// If key is greater than array[mid],
// then find in right subarray
else {
high = mid;
}
}
// If key is greater than last element which is
// array[n-1] then lower bound
// does not exists in the array
if (low < end && array[(int)low] <= key) {
low++;
}
// Returning the lower_bound index
return (int)low;
}
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 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();
}
}
}
class Pair implements Comparable<Pair>{
int lastOcc;
char ch;
public Pair(int lastOcc,char ch) {
this.lastOcc = lastOcc;
this.ch = ch;
}
public int compareTo(Pair p) {
return (this.lastOcc<p.lastOcc)?-1:1;
}
}
//class Pair implements Comparator<Pair>{
// int lastOcc;
// char ch;
// public Pair(int lastOcc,char ch) {
// this.lastOcc = lastOcc;
// this.ch = ch;
// }
//
//// static class PairComparator implements Comparator<Pair>{
// public int compare(Pair p1,Pair p2) {
// return (p1.lastOcc < p2.lastOcc) ? -1 : 1;
// }
//
//// }
//
//}
class Domino{
int a,b;
boolean visited;
public Domino(int a,int b) {
this.a = a;
this.b = b;
visited = 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 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 | 0cd5396ebaae322e48d025b021689933 | 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 in = new Scanner(System.in);
int t = in.nextInt();
for(int j=1;j<=t;j++)
{
int n = in.nextInt();
String s = in.next();
char ch1,ch2,ch3;
String ans="";
int i,v=0,w=0,y=0;
for(i=n-1;i>=2;i--)
{
ch1 = s.charAt(i);
ch2 = s.charAt(i-1);
ch3 = s.charAt(i-2);
if(ch1 != '0')
{
v = ch1 - '0';
ans = ans+(char)(96+v);
}
else
{
v = ch3 - '0';
w = ch2 - '0';
y = v*10+w;
ans = ans+(char)(96+y);
i=i-2;
}
}
if(i==1)
{
ch1 = s.charAt(i);
ch2 = s.charAt(i-1);
v = ch1 - '0';
ans = ans+(char)(96+v);
w = ch2 - '0';
ans = ans+(char)(96+w);
}
if(i==0)
{
ch1 = s.charAt(i);
v = ch1 - '0';
ans = ans+(char)(96+v);
}
StringBuilder sb = new StringBuilder(ans);
String res = sb.reverse().toString();
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 | 2e6f7fd43e5f7e8ff1f682047a245867 | 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 {
public static int pre_sum(int x)
{
if (x == 0)
return 0 ;
else
return x+pre_sum(x-1);
}
public static void Pro_A() throws IOException{
PrintWriter pw = new PrintWriter(System.out);
Scanner sc = new Scanner (System.in);
int q = sc.nextInt();
char arr [] = new char [27] ;
for (int i=1 ; i<arr.length ; i++)
{
arr[i] = ((char) ('a'+(i-1))) ;
}
while (q --> 0)
{
int num = sc.nextInt() ;
String s = sc.next() ;
int i= s.length()-1;
String st = "" ;
while(i>=0)
{
int n =Integer.parseInt(""+ s.charAt(i));
if (n == 0)
{
st= arr[Integer.parseInt(s.charAt(i-2)+""+ s.charAt(i-1))] + st ;
i-=3 ;
}
else
{
st= arr[Integer.parseInt(""+ s.charAt(i))] + st ;
i-=1 ;
}
}
pw.println(st) ;
}
pw.flush();
}
public static void main (String [] args) throws IOException
{
//System.out.println(0%10);
Pro_A();
}
static class Pair implements Comparable{
int x ;
int y ;
public Pair(int x, int y)
{
this.x = x;
this.y = y;
}
public int compareTo(Object o) {
Pair p = (Pair) o ;
if(p.y >= y )
return 1 ;
else
return -1;
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(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();
}
}
} | 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 | 2204e1fc8559d51ab2ddc61573f14c65 | 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 {
public static int pre_sum(int x)
{
if (x == 0)
return 0 ;
else
return x+pre_sum(x-1);
}
public static void Pro_A() throws IOException{
PrintWriter pw = new PrintWriter(System.out);
Scanner sc = new Scanner (System.in);
int q = sc.nextInt();
char arr [] = new char [27] ;
for (int i=1 ; i<arr.length ; i++)
{
arr[i] = ((char) ('a'+(i-1))) ;
}
while (q --> 0)
{
int num = sc.nextInt() ;
String s = sc.next() ;
int i= s.length()-1;
String st = "" ;
while(i>0)
{
int n = Integer.parseInt(""+ s.charAt(i-1))*10 + Integer.parseInt(""+ s.charAt(i));
if (n > 9 && n%10 != 0)
{
st= arr[n%10] + st ;
i-=1 ;
}
else if (n <= 9 && n!=0)
{
st= arr[n] + st ;
i-=1 ;
}
else if (n%10 ==0)
{
n = Integer.parseInt(""+ s.charAt(i-1)) +Integer.parseInt(""+ s.charAt(i-2)) *10 ;
st= arr[n] + st ;
i-=3 ;
}
}
if (i==0)
st = arr[Integer.parseInt(""+ s.charAt(0))] + st ;
pw.println(st) ;
}
pw.flush();
}
public static void main (String [] args) throws IOException
{
//System.out.println(0%10);
Pro_A();
}
static class Pair implements Comparable{
int x ;
int y ;
public Pair(int x, int y)
{
this.x = x;
this.y = y;
}
public int compareTo(Object o) {
Pair p = (Pair) o ;
if(p.y >= y )
return 1 ;
else
return -1;
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(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();
}
}
} | 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 | 4282fa4b935c6d88f62df766c7a90563 | 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 {
static int globalVariable = 123456789;
static String author = "pl728 on codeforces";
public static void main(String[] args) {
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
MathUtils mathUtils = new MathUtils();
ArrayUtils arrayUtils = new ArrayUtils();
int q = sc.ni();
while (q-- != 0) {
int n = sc.ni();
String s = sc.ns();
StringBuilder sb = new StringBuilder();
List<Integer> decode = new ArrayList<>();
// test for 00
//
if(s.length() < 3) {
for (int x = 0; x < s.length(); x++) {
decode.add(Character.getNumericValue(s.charAt(x)));
}
for (int j : decode) {
sb.append(Character.toChars(j + 96));
}
System.out.println(sb);
continue;
}
Stack<Integer> stack = new Stack<>();
int lastAdded = n - 1;
int i = n - 3;
while(i >= 0) {
if(s.charAt(i + 2) == '0') {
stack.push(Integer.parseInt(s.charAt(i) + "" + s.charAt(i + 1)));
lastAdded = i;
i -= 3;
} else {
stack.push(Character.getNumericValue(s.charAt(i + 2)));
lastAdded = i + 2;
i -= 1;
}
}
if(i == -3) {
} else if(i == -2) {
stack.push(Character.getNumericValue(s.charAt(0)));
} else if(i == -1) {
if(lastAdded == 1) {
stack.push(Character.getNumericValue(s.charAt(0)));
} else {
// from index 2
stack.push(Character.getNumericValue(s.charAt(1)));
stack.push(Character.getNumericValue(s.charAt(0)));
}
}
while (!stack.isEmpty()) {
sb.append(Character.toChars(stack.pop() + 96));
}
System.out.println(sb);
}
}
static class FastReader {
/**
* Uses BufferedReader and StringTokenizer for quick java I/O
* get next int, long, double, string
* get int, long, double, string arrays, both primitive and wrapped object when array contains all elements
* on one line, and we know the array size (n)
* next: gets next space separated item
* nextLine: returns entire line as space
*/
BufferedReader br;
StringTokenizer st;
public FastReader() {
this.br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
// to parse something else:
// T x = T.parseT(fastReader.next());
public int ni() {
return Integer.parseInt(next());
}
public String ns() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public String[] readStringArrayLine(int n) {
String line = "";
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return line.split(" ");
}
public String[] readStringArrayLines(int n) {
String[] result = new String[n];
for (int i = 0; i < n; i++) {
result[i] = this.next();
}
return result;
}
public int[] readIntArray(int n) {
int[] result = new int[n];
for (int i = 0; i < n; i++) {
result[i] = this.ni();
}
return result;
}
public long[] readLongArray(int n) {
long[] result = new long[n];
for (int i = 0; i < n; i++) {
result[i] = this.nl();
}
return result;
}
public Integer[] readIntArrayObject(int n) {
Integer[] result = new Integer[n];
for (int i = 0; i < n; i++) {
result[i] = this.ni();
}
return result;
}
public long nl() {
return Long.parseLong(next());
}
public char[] readCharArray(int n) {
return this.ns().toCharArray();
}
}
static class MathUtils {
public MathUtils() {
}
public long gcdLong(long a, long b) {
if (a % b == 0)
return b;
else
return gcdLong(b, a % b);
}
public long lcmLong(long a, long b) {
return a * b / gcdLong(a, b);
}
}
static class ArrayUtils {
public ArrayUtils() {
}
public static int[] reverse(int[] a) {
int n = a.length;
int[] b = new int[n];
int j = n;
for (int i = 0; i < n; i++) {
b[j - 1] = a[i];
j = j - 1;
}
return b;
}
public int sumIntArrayInt(int[] a) {
int ans = 0;
for (int i = 0; i < a.length; i++) {
ans += a[i];
}
return ans;
}
public long sumLongArrayLong(int[] a) {
long ans = 0;
for (int i = 0; i < a.length; i++) {
ans += a[i];
}
return ans;
}
}
public static int lowercaseToIndex(char c) {
return (int) c - 97;
}
public static int indexToLowercase(int i) {
return (char) i - 97;
}
}
| 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 | 0c70de900fba3141423dda7ba9d39901 | 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 rd820 {
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
long k = gcd(b, a % b);
return k;
}
static boolean flag = false;
public static void main(String[] args) {
FastScanner scn = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int T = scn.nextInt();
while(T-- > 0) {
int n = scn.nextInt();
flag = false;
String s = scn.next();
String res = "";
for(int i = n-1;i>=0;i--){
char ch = s.charAt(i);
if(ch != '0'){
int num = Integer.parseInt(ch + "");
res = (char)('a' + num-1) + res;
}
else{
int num = Integer.parseInt(s.substring(i-2,i+1));
num = num/10;
res = (char)('a' + num-1) + res;
i = i-2;
}
}
System.out.println(res);
}
out.close();
}
public static void helper(String s, int idx, String res, int cnt){
if(idx == s.length()){
if(flag == false && cnt == s.length()){
System.out.println(res);
flag = true;
}
return;
}
int num1 = Integer.parseInt(s.substring(idx,idx+1));
if(num1 != 0){
char ch = (char)('a' + (num1-1));
helper(s, idx+1, res + ch, cnt+1);
}
if(idx + 2 < s.length()){
int num2 = Integer.parseInt(s.substring(idx,idx+3));
if(num2 >= 100 && num2 <= 260){
int nums = num2/10;
char ch = (char)('a' + (nums-1));
helper(s, idx+3, res + ch,cnt+3);
}
}
}
static final Random random=new Random();
static final int mod=1_000_000_007;
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static long add(long a, long b) {
return (a+b)%mod;
}
static long sub(long a, long b) {
return ((a-b)%mod+mod)%mod;
}
static long mul(long a, long b) {
return (a*b)%mod;
}
static long exp(long base, long exp) {
if (exp==0) return 1;
long half=exp(base, exp/2);
if (exp%2==0) return mul(half, half);
return mul(half, mul(half, base));
}
static long[] factorials=new long[2_000_001];
static long[] invFactorials=new long[2_000_001];
static void precompFacts() {
factorials[0]=invFactorials[0]=1;
for (int i=1; i<factorials.length; i++) factorials[i]=mul(factorials[i-1], i);
invFactorials[factorials.length-1]=exp(factorials[factorials.length-1], mod-2);
for (int i=invFactorials.length-2; i>=0; i--)
invFactorials[i]=mul(invFactorials[i+1], i+1);
}
static long nCk(int n, int k) {
return mul(factorials[n], mul(invFactorials[k], invFactorials[n-k]));
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
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 | 6795475021d0d9648cd32d79fc4addc7 | 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 com.sun.security.jgss.GSSUtil;
import com.sun.source.tree.ModuleTree;
import org.w3c.dom.ls.LSOutput;
import java.io.*;
import java.sql.Array;
import java.util.*;
public class edu130 {
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();
}
}
public static boolean func(long x,long k){
return (k-((x*x)+(x)+1))%(2*x)==0;
}
public static void gg(int [] arr, int l, int r, int count , int[] ans){
if(r<l){
return;
}
if(r==l){
ans[l]=count;
return;
}
int m=l;
for(int i=l+1;i<=r;i++){
if(arr[i]>arr[m]){
m=i;
}
}
ans[m]=count;
gg(arr,l,m-1,count+1,ans);
gg(arr,m+1,r,count+1,ans);
}
public static void main(String[] args) {
//RSRRSRSSSR
try {
FastReader sc = new FastReader();
FastWriter out = new FastWriter();
int t=sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
String s=sc.next();
StringBuilder tt= new StringBuilder();
for(int i=n-1;i>=0;i--){
if(s.charAt(i)=='0'){
String ff="";
ff+=s.charAt(i-2);
ff+=s.charAt(i-1);
int a=Integer.parseInt(ff);
tt.append((char) ('a' + (a - 1)));
i-=2;
}else{
tt.append((char) ('a' + ((s.charAt(i) - '0') - 1)));
}
}
System.out.println(tt.reverse());
}
}catch(Exception e){
return;
}
}
public static int gg(int num){
int count=0;
while(num>0){
count++;
num=(num>>1);
}
return count;
}
private static void swap(long[] arr, int i, int ii) {
long temp=arr[i];
arr[i]=arr[ii];
arr[ii]=temp;
}
public static int lcm(int a,int b){
return (a/gcd(a,b))*b;
}
private static int gcd(int a, int b) {
if(b==0)return a;
return gcd(b,a%b);
}
static class Pair {
int a;
int b;
Pair(int a, int b) {
this.a = a;
this.b = 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 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 | fb1cb105f322ac84d471e4c0fff02d9e | 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 scanner = new Scanner(System.in);
int n = scanner.nextInt();
for(int j = 0; j < n; j++) {
int temp = scanner.nextInt();
String s = scanner.next();
String finalStr = "";
for(int i = s.length() - 1; i >= 0; i--) {
if(s.charAt(i) == '0') {
finalStr = String.valueOf((char)(Integer.parseInt(s.charAt(i - 2) + "" + s.charAt(i - 1)) + 96)) + finalStr;
i -= 2;
} else {
finalStr = String.valueOf((char)(Integer.parseInt(s.charAt(i) + "") + 96)) + finalStr;
}
}
System.out.println(finalStr);
}
scanner.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 | 6e3dd6e45f5232a0847319cdec35449d | 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_String_10 {
public static void main(String args[]) {
Scanner s = new Scanner(System.in); //
// total test cases
int t = s.nextInt();
while(t-->0) {
int n = s.nextInt(); // length of the string
String str1 = s.next();
String str2 = "";
// iterate over string from last
for(int i = n-1;i>=0;i--) {
if(str1.charAt(i)!='0') {
// get the alphabet corresponding to number 1-a , 2-b etc
// make integer of character using parse
String temp = str1.charAt(i)+"";
int t_temp = 96+Integer.parseInt(temp);
// ascii value of t_temp
str2 = (char)t_temp+str2;
}else {
i = i-2;
String temp = str1.charAt(i)+""+str1.charAt(i+1);
int t_temp = 96+Integer.parseInt(temp);
str2 = (char)t_temp+str2;
}
}
System.out.println(str2);
}
}
}
| 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 | 44160ecf439d04ba34a10bd9b7aab385 | 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_String_9 {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0) {
int n = s.nextInt();
String str1 = s.next();
String str2 = "";
for(int i = n-1;i>=0;i--) {
if(str1.charAt(i)!='0') {
String str3 = str1.charAt(i)+"";
str2 = (char)(96+Integer.parseInt(str3))+str2;
}else {
i = i-2;
String temp = str1.charAt(i)+""+str1.charAt(i+1);
int t3 = Integer.parseInt(temp);
str2=(char)(96+t3)+str2;
}
}
System.out.println(str2);
}
}
} | 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 | 98b991de2308482e5cedda1a4366c031 | 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[]) throws IOException {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while (test-- > 0)
{
int n =sc.nextInt();
String s=sc.next();
int i=s.length()-1,t;
String out="";
while(i>=0)
{
if(s.charAt(i)=='0')
{
t=Integer.parseInt(s.substring(i-2,i));
t=t+96;
out=(char)t+out;
i=i-3;
//System.out.println(out);
}
else
{
t=s.charAt(i)-48;
t=t+96;
out=(char)t+out;
i=i-1;
// System.out.println(out);
}
}
System.out.println(out);
}
sc.close();
}
}
// char d=(char)('a'-1+2);
// System.out.println(d);
//n=Integer.parseInt(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 | e025f7a35b10fca6dc32621c12eb596b | 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 Solutions {
public static void main( String[] args ) {
Scanner in = new Scanner( System.in );
int n = in.nextInt();
while( n --> 0 ) {
int m = in.nextInt();
String s = in.next();
StringBuilder sb = new StringBuilder( s );
String k = String.valueOf( sb.reverse());
String res = "";
char[] c = k.toCharArray();
for( int i = 0; i < k.length(); ++i ) {
if( c[i] != '0' ) {
res += ((char)( Integer.parseInt( String.valueOf( c[i] )) - 1 + 'a' ));
} else {
int sum = ( c[i + 2] - '0' ) * 10;
sum += c[i + 1] - '0';
res += ((char)( sum - 1 + 'a' ));
i += 2;
}
}
sb = new StringBuilder( res );
res = String.valueOf( sb.reverse());
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 | 09a977719cc2b423ceec7748af5fa36d | 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 Problem2{
public static void main (String[] args){
try{
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int t = scan(in);
while(t-->0){
int n = scan(in);
String s = in.next();
HashMap<String,String> map = new HashMap<>();
HashMap<String,String> mapa = new HashMap<>();
mapa.put("1","a");
mapa.put("2","b");
mapa.put("3","c");
mapa.put("4","d");
mapa.put("5","e");
mapa.put("6","f");
mapa.put("7","g");
mapa.put("8","h");
mapa.put("9","i");
map.put("100","j");
map.put("110","k");
map.put("120","l");
map.put("130","m");
map.put("140","n");
map.put("150","o");
map.put("160","p");
map.put("170","q");
map.put("180","r");
map.put("190","s");
map.put("200","t");
map.put("210","u");
map.put("220","v");
map.put("230","w");
map.put("240","x");
map.put("250","y");
map.put("260","z");
String arr[] = {"100",
"110",
"120",
"130",
"140",
"150",
"160",
"170",
"180",
"190",
"200",
"210",
"220",
"230",
"240",
"250",
"260"
};
String[] brr = {"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
};
String ans = "";
for(int i=0;i<n;i++){
boolean dual = false;
if(i+3<=n){
String sub = s.substring(i, i+3);
if(i+4<=n && s.charAt(i+3)!='0' && map.get(sub)!=null){
ans += map.get(sub);
dual = true;
i+=2;
}else if(i+3==n && map.get(sub)!=null){
ans += map.get(sub);
dual = true;
i+=2;
}
}
if(!dual){
if(mapa.get(""+s.charAt(i))!=null){
ans += mapa.get(""+s.charAt(i));
}
}
}
System.out.println(ans);
};
out.close();
}catch (Exception e) {
return;
}
}
public static int scan(FastReader sc){
return sc.nextInt();
}
public static int[] array(int n,FastReader sc){
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i] = scan(sc);
}
return arr;
}
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 close() throws IOException {
bw.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 | b15a24901fc44a28a3dd631cc909c0c0 | 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.*;
import java.util.*;
import java.io.*;
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();
int len = s.length();
StringBuilder sb = new StringBuilder();
for(int i = len - 1; i >= 0; --i) {
char c = s.charAt(i);
int idx = 0;
if(c == '0') {
idx = Integer.parseInt(s.substring(i - 2, i));
i -= 2;
} else {
idx = Integer.parseInt(c + "");
}
c = (char)('a' + idx - 1);
sb.append(c);
}
sb.reverse();
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 | f72a1c1394d08d30765634d3ca7a6429 | 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 name;
import java.util.*;
public class _1729B {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i=1;i<=t;i++)
{
solve(in);
}
}
public static void solve(Scanner in)
{
int n = in.nextInt();
String input = in.next();
char[] output = new char[n+1];
int position_output=0;
int i=n-1;
while(i>=0)
{
int id=0;
if(input.charAt(i)=='0')
{
id=(input.charAt(i-2)-'0')*10+input.charAt(i-1)-'0';
i-=3;
}
else
{
id=(input.charAt(i)-'0');
i--;
}
char out = (char) (id - 1 + 'a');
output[position_output] = out;
position_output++;
}
String out="";
for(i=position_output-1;i>=0;i--)
out=out+output[i];
System.out.println(out);
}
}
| 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 | f08b551b9653dca3767db41236044ccd | 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 HelloWorld {
public static void main(String args[]) {
Scanner scanner=new Scanner(System.in);
int t=scanner.nextInt();
while(t-->0) {
int len=scanner.nextInt();
scanner.nextLine();
String gs=scanner.nextLine();
String sb="";
int i=gs.length()-1;
char[] bits=gs.toCharArray();
while(i>=0) {
if(bits[i]=='0') {
sb=getChar((bits[i-2]-'0')*10+bits[i-1]-'0')+sb;
i-=3;
}
else {
sb=getChar(bits[i]-'0')+sb;
i--;
}
}
System.out.println(sb.toString());
}
scanner.close();
}
static char getChar(int i) {
return (char)(i+'a'-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 | 86dab54c75c47125f123ad79f2dc25fb | 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 className1{
public static void main(String args[]) {
Scanner scanner=new Scanner(System.in);
int numInputs=scanner.nextInt();
scanner.nextLine();
while(numInputs-->0) {
int NumDigits=scanner.nextInt();
scanner.nextLine();
String code=scanner.nextLine();
String decoded="";
char[] bits=code.toCharArray();
int p1=0;
int p2=0;
int index=bits.length-1;
while(index>=0) {
if(bits[index]=='0') {
decoded=getChar(Integer.parseInt(bits[index-2]+""+bits[index-1]+""))+decoded;
index-=3;
}
else {
decoded=getChar(Integer.parseInt(bits[index]+""))+decoded;
index--;
}
}
System.out.println(decoded);
}
}
static char getChar(int i) {
char c=(char) (i-1+97);
return c;
}
}
| 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 | e700364da7e23a9fc8909cf8b233f7c2 | 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.*;
public class Main
{
public static void main(String[] args)throws IOException
{
InputStreamReader Ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(Ir);
int a=Integer.parseInt(br.readLine());
String[] b=new String [a];
int[] c=new int[a];
for(int i=0;i<a;i++)
{
c[i]=Integer.parseInt(br.readLine());
b[i]=(br.readLine());
}
String s="";
String p="";
for(int j=0;j<a;j++)
{s="";
p="";
for(int i=c[j]-1;i>-1;i--)
{
if(b[j].charAt(i)=='0')
{
p=b[j].substring(i-2,i);
i=i-2;
}
else
{
p=b[j].substring(i,i+1);
}
p=Character.toString((char)(96+(Integer.parseInt(p))));
s=p+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 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 | d8add88d424b9161341d03574bed688c | 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){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0) {
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
StringBuilder res = new StringBuilder();
// System.out.println(s);
for(int i=n-1;i>=0;i--){
int x;
if(s.charAt(i) == '0'){
x = Integer.parseInt(s.substring(i-2, i));
i=i-2;
}
else{
x = s.charAt(i)-'0';
}
res.append((char)(x-1+'a'));
}
res.reverse();
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 | 61ccb51eea9b220186a3dbdfe13f42d3 | 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 decode {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String[] testcases = new String[t];
int[] testcaseslength=new int[t];
for (int i = 0; i < t; i++) {
testcaseslength[i] = sc.nextInt();
testcases[i] = sc.next();
}
int time = 0;
while (time < t) {
String str=testcases[time];
int marker;
String sub = "";
int len = str.length();
String result = "";
//ASCII code for a is 97 and that of z is 122
char ch;
for (int i = len - 1; i >= 0; i--) {
ch = str.charAt(i);
if (ch == '0') {
marker = i;
i = i - 2;
sub = str.substring(i, marker);
int vl = Integer.parseInt(sub);
result += (char) (vl + 96);
} else {
result += (char) ((ch - '0') + 96);
}
}
StringBuffer sb = new StringBuffer(result);
System.out.println(sb.reverse().toString());
time++;
}
}
}
| 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 | d2c95f2a0652a889ff85919a45def4b8 | 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 cf1729.cf1729b;
import java.util.Scanner;
public class CF1729B {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
int n = scanner.nextInt();
String code = scanner.next();
String result = cf1729b(n, code);
System.out.println(result);
}
scanner.close();
}
private static String cf1729b(int n, String code) {
String result = "";
for (int index = n - 1; index >= 0; index--) {
if (code.charAt(index) == '0') {
result = (char) (Integer.parseInt(code.substring(index - 2, index)) + 96) + result;
index -= 2;
} else {
result = (char) (code.charAt(index) + 48) + result;
}
}
return 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 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 | eb848c84ac21d816abb04853f520e53c | 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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class App {
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;
}
}
// END FastReader
public static void main(String[] args) {
FastReader s = new FastReader();
int q = s.nextInt();
String mapStr = "abcdefghijklmnopqrstuvwxyz";
HashMap<String, String> map = new HashMap<>();
for (int i = 0; i < q; i++) {
int n = s.nextInt();
String str = s.next();
if (!map.containsKey(str)) {
int j = n - 1;
Stack<Character> stack = new Stack<>();
while (j >= 0) {
if (str.charAt(j) == '0') {
int x = Integer.parseInt(str.substring(j - 2, j));
stack.push(mapStr.charAt(x - 1));
j -= 3;
} else {
stack.push(mapStr.charAt(str.charAt(j) - '1'));
j--;
}
}
StringBuilder sb = new StringBuilder();
while (!stack.isEmpty()) {
sb.append(stack.pop());
}
map.put(str, sb.toString());
System.out.println(sb);
} else {
System.out.println(map.get(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 | 21a74b56043bdd1d103c5d493f141f9b | 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.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class App {
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;
}
}
// END FastReader
public static void main(String[] args) {
FastReader s = new FastReader();
int q = s.nextInt();
String mapStr = "abcdefghijklmnopqrstuvwxyz";
HashMap<String, String> map = new HashMap<>();
for (int i = 0; i < q; i++) {
int n = s.nextInt();
String str = s.next();
int j = n - 1;
Stack<Character> stack = new Stack<>();
while (j >= 0) {
if (str.charAt(j) == '0') {
int x = Integer.parseInt(str.substring(j - 2, j));
stack.push(mapStr.charAt(x - 1));
j -= 3;
} else {
stack.push(mapStr.charAt(str.charAt(j) - '1'));
j--;
}
}
StringBuilder sb = new StringBuilder();
while (!stack.isEmpty()) {
sb.append(stack.pop());
}
map.put(str, sb.toString());
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 | 3b60801446d980a77ef3d949caf9e801 | 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 String algorithm(String st){
String ans = "";
for(int i=st.length()-1;i>=0;){
if(st.charAt(i)=='0'){
String temp = st.substring(i-2,i);
int a = Integer.parseInt(temp);
ans += (char)(a+97-1);
i = i-3;
}else{
int a = Integer.parseInt(st.substring(i,i+1));
char b = (char)(a+97-1);
ans += b;
i--;
}
}
StringBuilder sb = new StringBuilder(ans);
sb.reverse();
return sb.toString();
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int i=0;i<t;i++){
int n = s.nextInt();
String st = s.next();
System.out.println(algorithm(st));
}
}
}
| 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 | 5d76c8a9fd0e0acc7093e19aeb093deb | 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 wef {
public static void main(String[] args) {
Scanner key=new Scanner(System.in);
int t=key.nextInt();
for(int i=0;i<t;i++){
int n=key.nextInt();
key.nextLine();
String str=key.nextLine();
String temp="";
String temp1="";
int temp2;
char temp3;
for(int g=n-1;g>=0;g--){
if((g-2)>=0){
if(str.charAt(g)=='0'){
temp1=str.substring(g-2,g);
temp2=((((int)temp1.charAt(0))-48)*10)+(((int)temp1.charAt(1))-48)+96;
temp3=(char)temp2;
temp=temp+temp3;
g-=2;
}else{
temp2=(((int)str.charAt(g))-48)+96;
temp3=(char)temp2;
temp=temp+temp3;
}
}else{
temp2=(((int)str.charAt(g))-48)+96;
temp3=(char)temp2;
temp=temp+temp3;
}
}
temp1="";
for(int j=temp.length()-1;j>=0;j--) {
temp1=temp1+temp.charAt(j);
}
System.out.println(temp1);
}
}
}
| 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 | 472b4909bbe3a594a0afa328ae76c989 | 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.HashMap;
public class Experts {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
HashMap<Integer,Character>map=new HashMap();
int a=1;
for(char i='a';i<='z';i++){
map.put(a,i);
a++;
}
long t=input.nextLong();
while(t>=1){
String temp="";
String ex="";
String temp2="";
int length=input.nextInt();
String b=input.next();
for(int i=b.length()-1;i>=0;i--){
ex="";
if(b.charAt(i)=='0'){
ex+=b.charAt(i-2)-'0';
ex+=b.charAt(i-1)-'0';
int h=Integer.parseInt(ex);
temp+=map.get(h);
i--;
i--;
}
else{
temp+=map.get(b.charAt(i)-'0');
}
}
for(int i=temp.length()-1;i>=0;i--){
temp2+=temp.charAt(i);}
System.out.println(temp2);
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 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 | 50f466b95baa18a5330553ebf6c60e93 | 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 Mainn {
static long M = (long) (1e9 + 7);
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 swap(int[] a, long i, long j) {
long temp = a[(int) i];
a[(int) i] = a[(int) j];
a[(int) j] = (int) temp;
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static int lcm(int a, int b) {
return (int) (a * b / gcd(a, b));
}
public static String sortString(String inputString) {
char[] tempArray = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static boolean isSquare(int n) {
int v = (int) Math.sqrt(n);
return v * v == n;
}
static boolean PowerOfTwo(int n) {
if (n == 0) return false;
return (int) (Math.ceil((Math.log(n) / Math.log(2)))) ==
(int) (Math.floor(((Math.log(n) / Math.log(2)))));
}
static int power(long a, long b) {
long res = 1;
while (b > 0) {
if (b % 2 == 1) {
res = (res * a) % M;
}
a = ((a * a) % M);
b = b / 2;
}
return (int) res;
}
public static boolean isPrime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) {
return false;
}
return true;
}
static long computeXOR(long n) {
if (n % 4 == 0)
return n;
if (n % 4 == 1)
return 1;
if (n % 4 == 2)
return n + 1;
return 0;
}
static long binaryToInteger(String binary) {
char[] numbers = binary.toCharArray();
long result = 0;
for (int i = numbers.length - 1; i >= 0; i--)
if (numbers[i] == '1')
result += Math.pow(2, (numbers.length - i - 1));
return result;
}
static String reverseString(String str) {
char ch[] = str.toCharArray();
String rev = "";
for (int i = ch.length - 1; i >= 0; i--) {
rev += ch[i];
}
return rev;
}
static int countFreq(int[] arr, int n) {
HashMap<Integer, Integer> map = new HashMap<>();
int x = 0;
for (int i = 0; i < n; i++) {
map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
if (map.get(arr[i]) == 1)
x++;
}
return x;
}
static void reverse(int[] arr, int l, int r) {
int d = (r - l + 1) / 2;
for (int i = 0; i < d; i++) {
int t = arr[l + i];
arr[l + i] = arr[r - i];
arr[r - i] = t;
}
}
static void sort(String[] s, int n) {
for (int i = 1; i < n; i++) {
String temp = s[i];
int j = i - 1;
while (j >= 0 && temp.length() < s[j].length()) {
s[j + 1] = s[j];
j--;
}
s[j + 1] = temp;
}
}
static int sqr(int n) {
double x = Math.sqrt(n);
if ((int) x == x)
return (int) x;
else
return (int) (x + 1);
}
static class Pair implements Comparable<Pair> {
int start, end;
public Pair(int x, int y) {
this.start = x;
this.end = y;
}
@Override
public int compareTo(Pair p) {
if (start == p.start) {
return end - p.end;
}
return start - p.start;
}
}
static int set_bits_count(int num) {
int count = 0;
while (num > 0) {
num &= (num - 1);
count++;
}
return count;
}
static double factorial(double n) {
double f = 1;
for (int i = 1; i <= n; i++) {
f = f * i;
}
return f;
}
static boolean palindrome(int arr[], int n) {
boolean flag = true;
for (int i = 0; i <= n / 2 && n != 0; i++) {
if (arr[i] != arr[n - i - 1]) {
flag = false;
break;
}
}
return flag;
}
public static boolean isSorted(int[] a) {
if (a == null || a.length <= 1) {
return true;
}
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
public static boolean Consecutive(List<Integer> a, int[] b, int n, int m) {
int i = 0, j = 0;
while (i < n && j < m) {
if (Objects.equals(a.get(i), b[j])) {
i++;
j++;
if (j == m)
return true;
} else {
i = i - j + 1;
j = 0;
}
}
return false;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- != 0) {
int n = sc.nextInt();
String s = sc.next();
StringBuilder sb = new StringBuilder();
for(int i=s.length()-1; i>=0; i--) {
if(s.charAt(i) == '0') {
int x = Integer.parseInt(s.substring(i-2, i));
sb.append((char)('a'+(x-1)));
i-=2;
} else {
int c = s.charAt(i)-'0';
sb.append((char)('a'+c-1));
}
}
sb = sb.reverse();
System.out.println(sb.toString());
}
}
static void solve() throws IOException {
}
}
| 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 | 080abde0ab2868bee58339b865a00e53 | 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 Mainn {
static StringBuilder sb = new StringBuilder();
static long M = (long) (1e9 + 7);
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 swap(int[] a, long i, long j) {
long temp = a[(int) i];
a[(int) i] = a[(int) j];
a[(int) j] = (int) temp;
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static int lcm(int a, int b) {
return (int) (a * b / gcd(a, b));
}
public static String sortString(String inputString) {
char[] tempArray = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static boolean isSquare(int n) {
int v = (int) Math.sqrt(n);
return v * v == n;
}
static boolean PowerOfTwo(int n) {
if (n == 0) return false;
return (int) (Math.ceil((Math.log(n) / Math.log(2)))) ==
(int) (Math.floor(((Math.log(n) / Math.log(2)))));
}
static int power(long a, long b) {
long res = 1;
while (b > 0) {
if (b % 2 == 1) {
res = (res * a) % M;
}
a = ((a * a) % M);
b = b / 2;
}
return (int) res;
}
public static boolean isPrime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) {
return false;
}
return true;
}
static long computeXOR(long n) {
if (n % 4 == 0)
return n;
if (n % 4 == 1)
return 1;
if (n % 4 == 2)
return n + 1;
return 0;
}
static long binaryToInteger(String binary) {
char[] numbers = binary.toCharArray();
long result = 0;
for (int i = numbers.length - 1; i >= 0; i--)
if (numbers[i] == '1')
result += Math.pow(2, (numbers.length - i - 1));
return result;
}
static String reverseString(String str) {
char ch[] = str.toCharArray();
String rev = "";
for (int i = ch.length - 1; i >= 0; i--) {
rev += ch[i];
}
return rev;
}
static int countFreq(int[] arr, int n) {
HashMap<Integer, Integer> map = new HashMap<>();
int x = 0;
for (int i = 0; i < n; i++) {
map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
}
for (int i = 0; i < n; i++) {
if (map.get(arr[i]) == 1)
x++;
}
return x;
}
static void reverse(int[] arr, int l, int r) {
int d = (r - l + 1) / 2;
for (int i = 0; i < d; i++) {
int t = arr[l + i];
arr[l + i] = arr[r - i];
arr[r - i] = t;
}
}
static void sort(String[] s, int n) {
for (int i = 1; i < n; i++) {
String temp = s[i];
int j = i - 1;
while (j >= 0 && temp.length() < s[j].length()) {
s[j + 1] = s[j];
j--;
}
s[j + 1] = temp;
}
}
static int sqr(int n) {
double x = Math.sqrt(n);
if ((int) x == x)
return (int) x;
else
return (int) (x + 1);
}
static class Pair implements Comparable<Pair> {
int start, end;
public Pair(int x, int y) {
this.start = x;
this.end = y;
}
@Override
public int compareTo(Pair p) {
if (start == p.start) {
return end - p.end;
}
return start - p.start;
}
}
static int set_bits_count(int num) {
int count = 0;
while (num > 0) {
num &= (num - 1);
count++;
}
return count;
}
static double factorial(double n) {
double f = 1;
for (int i = 1; i <= n; i++) {
f = f * i;
}
return f;
}
static boolean palindrome(int arr[], int n) {
boolean flag = true;
for (int i = 0; i <= n / 2 && n != 0; i++) {
if (arr[i] != arr[n - i - 1]) {
flag = false;
break;
}
}
return flag;
}
public static boolean isSorted(int[] a) {
if (a == null || a.length <= 1) {
return true;
}
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
public static boolean Consecutive(List<Integer> a, int[] b, int n, int m) {
int i = 0, j = 0;
while (i < n && j < m) {
if (Objects.equals(a.get(i), b[j])) {
i++;
j++;
if (j == m)
return true;
} else {
i = i - j + 1;
j = 0;
}
}
return false;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- != 0) {
int n = sc.nextInt();
String s = sc.next();
String res="";
for(int j=s.length()-1; j>=0; j--) {
if(s.charAt(j)!='0') {
res=(char)((96 + s.charAt(j)) - '0') + res;
}
else {
j = j-2;
String temp= "" + (char)s.charAt(j) + (char)s.charAt(j+1);
res=(char)(96 + Integer.parseInt(temp)) + res;
}
}
System.out.println(res);
}
}
static void solve() throws IOException {
}
}
| 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 | cd98a0bc7434de3578747019c2195a80 | 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 wef {
public static void main(String[] args) {
Scanner key=new Scanner(System.in);
int t=key.nextInt();
for(int i=0;i<t;i++){
int n=key.nextInt();
key.nextLine();
String str=key.nextLine();
String temp="";
String temp1="";
int temp2;
char temp3;
for(int g=n-1;g>=0;g--){
if((g-2)>=0){
if(str.charAt(g)=='0'){
temp1=str.substring(g-2,g);
temp2=((((int)temp1.charAt(0))-48)*10)+(((int)temp1.charAt(1))-48)+96;
temp3=(char)temp2;
temp=temp+temp3;
g-=2;
}else{
temp2=(((int)str.charAt(g))-48)+96;
temp3=(char)temp2;
temp=temp+temp3;
}
}else{
temp2=(((int)str.charAt(g))-48)+96;
temp3=(char)temp2;
temp=temp+temp3;
}
temp1="";
for(int j=temp.length()-1;j>=0;j--) {
temp1=temp1+temp.charAt(j);
}
}
System.out.println(temp1);
}
}
}
| 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 | c11ec6912c89d625a08a5718dbd94231 | 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.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
public class Round820B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] alphabets = new String[27];
char alphabet = 97;
for(int i = 1; i < alphabets.length; i++) {
alphabets[i] = String.valueOf(alphabet);
alphabet++;
}
int q = Integer.parseInt(br.readLine());
for(int i = 0; i < q; i++) {
int n = Integer.parseInt(br.readLine());
String decodeTarget = br.readLine();
Deque<String> decodeList = new ArrayDeque<>();
for(int j = 0; j < decodeTarget.length(); j++) {
if(decodeList.size() > 0 && decodeList.peekLast().equals("0")) {
if(decodeTarget.charAt(j) == '0') {
String units = decodeList.pollLast();
String tens = decodeList.pollLast();
decodeList.add(tens + units);
} else {
decodeList.pollLast();
String units = decodeList.pollLast();
String tens = decodeList.pollLast();
decodeList.add(tens + units);
decodeList.add(String.valueOf(decodeTarget.charAt(j)));
}
} else {
decodeList.add(String.valueOf(decodeTarget.charAt(j)));
}
}
if(decodeList.peekLast().equals("0")) {
decodeList.pollLast();
String units = decodeList.pollLast();
String tens = decodeList.pollLast();
decodeList.add(tens + units);
}
StringBuilder sb = new StringBuilder();
for(String unit : decodeList) {
sb.append(alphabets[Integer.parseInt(unit)]);
}
bw.write(sb + "\n");
}
bw.flush();
bw.close();
br.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 | bd12e1b6979e41bc47162c361f0a4a16 | 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 Codefor {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++){
int x=sc.nextInt();
String s=sc.next();
String c="abcdefghijklmnopqrstuvwxyz";
String end="";
if (x>=3){
for (int j=0;j<x-2;j++){
if (s.charAt(j+2)!='0'){
int v=s.charAt(j)-49;
end+=c.charAt(v);
v=0;
}
else {
if (j<x-3&&s.charAt(j+3)=='0'){
int v=s.charAt(j)-49;
end+=c.charAt(v);
v=(((int)s.charAt(j+1)-48)*10)+(int)s.charAt(j+2)-49;
end+=c.charAt(v);
j+=3;
v=0;
}
else{
int v=(((int)s.charAt(j)-48)*10)+(int)s.charAt(j+1)-49;
end+=c.charAt(v);
j+=2;
v=0;
}
}
}
if (s.charAt(x-1)!='0'&&s.charAt(x-2)!='0'){
end +=c.charAt(s.charAt(x-2)-49);
end+=c.charAt(s.charAt(x-1)-49);
}
else if (s.charAt(x-2)=='0'&&s.charAt(x-1)!='0'){
end+=c.charAt(s.charAt(x-1)-49);
}
}
else if (x==1)end+=c.charAt(s.charAt(x-1)-49);
else if (x==2){
if (s.charAt(1)=='0'){
int v=(((int)s.charAt(0)-48)*10)+(int)s.charAt(1)-49;
end+=c.charAt(v);
}
else {
end +=c.charAt(s.charAt(0)-49);
end+=c.charAt(s.charAt(1)-49);
}
}
System.out.println(end);
}
}} | 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 | e535ddc6b0fec5a6dd6a045f1567b96e | 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 k = sc.nextInt();
sc.nextLine();
while(k-->0){
sc.nextLine();
String s = sc.nextLine()+"p";
Stack<String> stack = new Stack<>();
String res = "";
for(int i = 0; i < s.length() - 1 ; ++i){
char ch = s.charAt(i);
String l = "" + ch;
if(ch == '0'){
if(s.charAt(i+1) != '0'){
String te = stack.pop();
te = stack.pop() + te;
int an = Integer.parseInt(te);
//System.out.println(te);
String re = ""+(char)(96+an) ;
String ten = "";
while(!stack.empty()){
ten = ""+(char)(96+Integer.parseInt(stack.pop()))+ten;
}
res += ten + re;
}else if(s.charAt(i+1) == '0'){
i++;
String ten = stack.pop().equals("1")? "j" : "t";
while(!stack.empty()){
ten = ""+(char)(96+Integer.parseInt(stack.pop()))+ten;
}
res += ten;
}
}else{
stack.push(l);
}
}
String tem = "";
while(!stack.empty()){
tem = ""+(char)(96+Integer.parseInt(stack.pop()))+tem;
}
res = res + tem;
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 | 9f383c7369a090c8942df24b1d833434 | 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 whatever //do not write package name here */
import java.io.*;
import java.util.Scanner;
public class b {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int testc = sc.nextInt();
for(int i=0;i<testc;i++){
int a = sc.nextInt();
sc.nextLine();
StringBuilder s = new StringBuilder();
// long num= sc.nextInt();
String S=sc.nextLine();
while(S.length()>0){
long val =0;
if(S.charAt(S.length()-1)=='0'){
val = Integer.parseInt(S.substring(S.length()-3,S.length()-1));
S=S.substring(0,S.length()-3);
}
else{
val = Integer.parseInt(S.substring(S.length()-1,S.length()));
S=S.substring(0,S.length()-1);
}
s.append((char)(96+val));
}
System.out.println(s.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 | 28a492348f0dcf951caaf1b89710fa7d | 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.InputStreamReader;
import java.io.PrintWriter;
public class B {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
static char[]ch = new char[28];
public static void main(String[] args)throws Exception {
for(int i = 1; i <= 26; i++) {
ch[i] = (char)(i + 96);
}
int t = Integer.parseInt(br.readLine());
while((t--) > 0) {
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
char c[] = s.toCharArray();
for(int i = 0; i < n; i++) {
if((i + 2) < n && c[i + 2] == '0') {
if(i + 3 < n && c[i + 3] == '0') {
out.print(ch[c[i] - '0']);
}
else {
int d1 = c[i] - '0';
int d2 = c[++i] - '0';
int d = d1 * 10 + d2;
out.print(ch[d]);
// System.out.print(d);
i++;
}
}else {
out.print(ch[c[i] - '0']);
}
}
out.println();
}
out.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 | 654710975936925685e303b65cde45ff | 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();
for(int i=0;i<t;i++){
int n = sc.nextInt();
String s = sc.next();
Map<Integer, String> map=new HashMap<>();
for(int j=1;j<=26;j++)
{
map.put(j,(char)(96+j)+"");
}
String res="";
for(int j=n-1;j>=0;j--){
if(s.charAt(j)=='0')
{
res=map.get(Integer.parseInt(s.charAt(j-2)+""+s.charAt(j-1)))+res;
j-=2;
}
else{
res=map.get(Integer.parseInt(s.charAt(j)+""))+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 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 | 5f08390474fa0a39aea77d6ccdf2ac9f | 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 Decode_String {
public static void main(String[] args) {
Scanner Scan = new Scanner(System.in);
//System.out.println("Test Cases :");
int t = Scan.nextInt();
int t1=0;
while(t1<t) {
t1++;
ArrayList<Character> List1 = new ArrayList<>(Arrays.asList(
'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'));
ArrayList<String> List2 = new ArrayList<>();
//System.out.println("Enter n :");
int n = Scan.nextInt();
//System.out.println("Enter s :");
String S = Scan.next();
//STEP 1
for(int i=(n-1); i>=0; i--){
if(S.charAt(i)=='0') {
String d =S.charAt(i-2)+""+S.charAt(i-1);
List2.add(d);
i-=2;
}
else {
String d =""+S.charAt(i);
List2.add(d);
}
}
//STEP 2
String Res ="";
for(int i=List2.size()-1; i>=0; i--) {
int e = Integer.valueOf(List2.get(i));
Res+=List1.get(e-1);
}
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 | 624f283f236555a8c458d7bf24f3ea19 | 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 Decode {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int numberOfSets = Integer.parseInt(br.readLine());
for (int nos = 0; nos < numberOfSets; nos ++) {
int size = Integer.parseInt(br.readLine());
int [] code = Arrays.stream(br.readLine().split("")).mapToInt(Integer::parseInt).toArray();
StringBuilder result = new StringBuilder();
for (int i = size-1; i>=0; i--) {
if (code[i] == 0) {
result.append((char)(code[i-2]*10+code[i-1]+'a'-1));
i-=2;
} else {result.append((char)(code[i]+'a'-1));}
}
System.out.println(result.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 | 710583a5a0a53b4cb98afbffa6941a81 | 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 Sulution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
String output = "";
int length=s.length();
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);
}
}
public static int gcd(int a,int b)
{
if(a==0)
return b;
return gcd(b,b%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 | 0f22f41dca59401b45a8398ee710c11f | 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.lang.StringBuffer;
/**
*
* @author ADNAN MUHAISEN
*/
public class JavaApplication157 {
public static void main(String[] args) {
Scanner in=new Scanner (System.in);
int t=in.nextInt();
for (int i = 0; i < t; i++) {
int n=in.nextInt();
String s=in.next();
StringBuffer re=new StringBuffer();
for (int j = s.length()-1; j >=0 ; j--) {
if(s.charAt(j)=='0'){
int x=(((int)s.charAt(j-2))-48) *10 +((int)s.charAt(j-1))-48;
re.insert(0, (char)(x+96));
j-=2;
}
else{
int x=(int)s.charAt(j)-48;
re.insert(0, (char)(x+96));
}
}
System.out.println(re);
}
}
}
| 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 | dd29010d2bd54aa9d852054d08996db8 | 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.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
for(int w=1;w<=t;w++)
{
int n = scn.nextInt();
scn.nextLine();
String s = scn.nextLine();
StringBuilder sb = new StringBuilder();
int i = 0;
while(i<n)
{
char c = s.charAt(i);
if(c=='0')
{
if(i==n-1)
{
int p = sb.length()-2;
sb = sb.delete(p,sb.length());
String x = s.substring(i-2,i);
int n1 = Integer.parseInt(x);
char get = (char)(96+n1);
sb.append(get+"");
break;
}
else
{
if(s.charAt(i+1)!='0')
{int p = sb.length()-2;
sb = sb.delete(p,sb.length());
String x = s.substring(i-2,i);
int n1 = Integer.parseInt(x);
char get = (char)(96+n1);
sb.append(get+"");
i+=1;
continue;}
else
{
int p = sb.length()-1;
sb = sb.delete(p,sb.length());
String x = s.substring(i-1,i+1);
int n1 = Integer.parseInt(x);
char get = (char)(96+n1);
sb.append(get+"");
i+=2;
continue;
}
}
}
else
{
int num = c-'0';
char x = (char)(96+num);
sb.append(x+"");
}
i++;}
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 | edcd042bb8a8c1bfe68761b5a45e5ecf | 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 B {
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();
sc.nextLine();
String str = sc.nextLine();
char [] ch = str.toCharArray();
// sc.nextLine();
if(str.length() == 1)
{
// System.out.println("len was 1");
System.out.println((char)(96 + Character.getNumericValue(ch[0])));
}
else
{
StringBuffer sb = new StringBuffer();
for(int j = n - 1; j >= 0; )
{
if(ch[j] == '0')
{
// System.out.println("Found 0!");
// System.out.println("Working with" + ch[j-2] + " " + ch[j-1]);
sb.append(
(char)
(
96 +
Character.getNumericValue(ch[j-2]) * 10 +
Character.getNumericValue(ch[j-1])
)
);
j -= 3;
}
else
{
// System.out.println("Not Found 0!");
sb.append(
(char)
(96 + Character.getNumericValue(ch[j]))
);
j--;
}
}
sb.reverse();
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 | 815d8bd9592aa34040e7602d8b9327e2 | 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.List;
import java.util.Scanner;
public class BDecodeString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String ans1 = "";
while (t > 0) {
int n = sc.nextInt();
String s = sc.next();
// sc.nextLine();
int a = 0;
outers:
while (a < n) {
int f = s.charAt(a) - '0' - 1;
if (f == -1) {
a += 1;
continue outers;
}
if (a + 2 < s.length() && f< 3) {
if (s.charAt(a + 2) > '6') {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
}
if (s.charAt(a + 2) == '0') {
if (a + 3 < s.length()) {
if (s.charAt(a + 3) == '0') {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
} else {
int in = Integer.parseInt(s.substring(a, a + 2)) - 1;
ans1 += ((char) ('a' + in));
a += 3;
continue outers;
}
} else {
int in = Integer.parseInt(s.substring(a, a + 2)) - 1;
ans1 += ((char) ('a' + in));
a += 3;
continue outers;
}
} else {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
}
} else {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
}
}
System.out.println(ans1);
ans1 = "";
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 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 | e19f2be88b36001576ed017c7aba7660 | 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.List;
import java.util.Scanner;
public class BDecodeString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String ans1 = "";
while (t > 0) {
int n = sc.nextInt();
String s = sc.next();
// sc.nextLine();
int a = 0;
outers:
while (a < n) {
int f = s.charAt(a) - '0' - 1;
if (f == -1) {
a += 1;
continue outers;
}
if (a + 2 < s.length() && f< 3) {
if (s.charAt(a + 2) > '6') {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
}
if (s.charAt(a + 2) == '0') {
if (a + 3 < s.length()) {
if (s.charAt(a + 3) == '0') {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
} else {
int in = Integer.parseInt(s.substring(a, a + 2)) - 1;
ans1 += ((char) ('a' + in));
a += 3;
continue outers;
}
} else {
int in = Integer.parseInt(s.substring(a, a + 2)) - 1;
ans1 += ((char) ('a' + in));
a += 3;
continue outers;
}
} else {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
}
} else {
ans1 += ((char) ('a' + f));
a += 1;
continue outers;
}
}
System.out.println(ans1);
ans1 = "";
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 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 | 16bd2c598df7442f941e2d34af423f09 | 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 OneSevenTwoNineB {
public static String decode(String t) {
String code = "";
for (int i = t.length() - 1; i >= 0; i--) {
if (t.charAt(i) == '0') {
int k = Integer.parseInt(t.substring(i - 2, i)) + 96;
char kh = (char) k;
code += kh;
i -= 2;
}
else {
int s = t.charAt(i) - '0' + 96;
char sh = (char) s;
code += sh;
}
}
StringBuffer rev = new StringBuffer(code);
rev.reverse();
return rev.toString();
}
public static void main(String[] args) {
Scanner w = new Scanner(System.in);
int q = w.nextInt(); //number of test cases
for (int i = 0; i < q; i++) {
int n = w.nextInt();
String t = w.next();
System.out.println(decode(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 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 | a7c1f0e8da0fc953b8e7c26551694d39 | 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.lang.*;
import java.util.stream.*;
import java.util.stream.Collectors;
public class Main {
static FastReader sc = new FastReader();
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 int calcdiv2(int n) {
int counter = 0;
while( ( 1 & n) != 1) {
n = n>>1;
counter++;
}
return counter;
}
public static int highestPowerOfTwo(int n) {
if((n & (n-1)) == 0) return n;
return n & (n-1);
}
public static boolean isPowerOfTwo(int n) {
return (n & (n-1)) == 0;
}
public static int valueOfRightMostSetBit(int n) {
return (n & (-n));
}
// public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm)
// {
// HashMap<Integer, Integer> temp
// = hm.entrySet()
// .stream()
// .sorted((i1, i2)
// -> i1.getValue().compareTo(
// i2.getValue()))
// .collect(Collectors.toMap(
// Map.Entry::getKey,
// Map.Entry::getValue,
// (e1, e2) -> e1, LinkedHashMap::new));
// return temp;
// }
// static int[] sortint(int a[]) {
// ArrayList<Integer> al = new ArrayList<>();
// for (int i : a) {
// al.add(i);
// }
// Collections.sort(al);
// for (int i = 0; i < a.length; i++) {
// a[i] = al.get(i);
// }
// return a;
// }
// static long[] sortlong(long a[]) {
// ArrayList<Long> al = new ArrayList<>();
// for (long i : a) {
// al.add(i);
// }
// Collections.sort(al);
// for (int i = 0; i < al.size(); i++) {
// a[i] = al.get(i);
// }
// return a;
// }
// static ArrayList<Integer> primesTilN(int n) {
// boolean p[] = new boolean[n + 1];
// ArrayList<Integer> al = new ArrayList<>();
// Arrays.fill(p, true);
// int i = 0;
// for (i = 2; i * i <= n; i++) {
// if (p[i] == true) {
// al.add(i);
// for (int j = i * i; j <= n; j += i) {
// p[j] = false;
// }
// }
// }
// for (i = i; i <= n; i++) {
// if (p[i] == true) {
// al.add(i);
// }
// }
// return al;
// }
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
// static long gcd(long a, long b) {
// if (a == 0) {
// return b;
// }
// return gcd(b % a, a);
// }
// static long pow(long x, long y) {
// long result = 1;
// while (y > 0) {
// if (y % 2 == 0) {
// x = x * x;
// y = y / 2;
// } else {
// result = result * x;
// y = y - 1;
// }
// }
// return result;
// }
// static boolean[] esieve(int n) {
// boolean p[] = new boolean[n + 1];
// Arrays.fill(p, true);
// for (int i = 2; i * i <= n; i++) {
// if (p[i] == true) {
// for (int j = i * i; j <= n; j += i) {
// p[j] = false;
// }
// }
// }
// return p;
// }
static int[] readarr(int n) {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
return arr;
}
// static HashMap<Integer, Integer> mapCounter(int arr[]) {
// for(int i : arr) {
// if(map.containsKey(i)) map.put(arr[i], map.get(arr[i])+1);
// else map.put(arr[i], 1);
// }
// }
static HashMap<Integer, Integer> mapCounter(int arr[]) {
HashMap<Integer, Integer> map = new HashMap<>();
for(int i : arr) {
if(map.containsKey(i)) map.put(i, map.get(i)+1);
else map.put(i, 1);
}
return map;
}
static double calcDistance(int x, int y, int a, int b) {
return Math.sqrt(Math.pow(x-a, 2) + Math.pow(y-b, 2));
}
static void printarr(int arr[]) {
System.out.println(Arrays.toString(arr));
}
public static HashMap<Integer, String> byValueS(HashMap<Integer, String> map) {
List<Map.Entry<Integer, String>> list = new LinkedList<>(map.entrySet());
Collections.sort(list, new Comparator<HashMap.Entry<Integer, String>>() {
public int compare(Map.Entry<Integer, String> o1, Map.Entry<Integer, String> o2) {
return o1.getValue().compareTo(o2.getValue());
}
}) ;
HashMap<Integer, String> map2 = new LinkedHashMap<>();
for(Map.Entry<Integer, String> i : list) {
map2.put(i.getKey(), i.getValue());
}
return map2;
}
public static HashMap<Integer, Integer> byValueI(HashMap<Integer, Integer> map) {
List<Map.Entry<Integer, Integer>> list = new LinkedList<>(map.entrySet());
Collections.sort(list, new Comparator<HashMap.Entry<Integer, Integer>>() {
public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
}
}) ;
HashMap<Integer, Integer> map2 = new LinkedHashMap<>();
for(Map.Entry<Integer, Integer> i : list) {
map2.put(i.getKey(), i.getValue());
}
return map2;
}
public static void main(String[] args)
{
int testcases = sc.nextInt();
outerrrr:
while (testcases-- > 0) {
int n = sc.nextInt();
String str = sc.next();
String res = "";
for(int i = 0; i < str.length(); i++ ) {
if(i+2 < str.length() && str.charAt(i+2) == '0' ) {
if(i+3 < str.length() && str.charAt(i+3) == '0' ) {
int a = str.charAt(i)-'0';
res += (char)(a+96);
}
else {
int a = (str.charAt(i) - '0') *10 + (str.charAt(i+1) - '0');
res += ((char)(a + 96));
i += 2;
}
}
else {
int a = str.charAt(i)-'0';
res += (char)(a+96);
}
}
System.out.println(res);
/*///////////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------END OF 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 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 | c2c4de12f0f7d286b33a90a8529d9773 | 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 {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int q = scanner.nextInt();
for (int qq = 0; qq < q; qq++) {
int n = scanner.nextInt();
String t = scanner.next();
System.out.println(decode(t));
}
}
private static String decode(String s) {
StringBuilder sb = new StringBuilder();
for (int i = s.length() - 1; i >= 0; i--) {
char c = s.charAt(i);
if (c == '0') {
sb.append((char) ('a' + Integer.parseInt("" + s.charAt(i - 2) + s.charAt(i - 1)) - 1));
i -= 2;
} else {
sb.append((char) ('a' + Character.digit(c, 10) - 1));
}
}
return sb.reverse().toString();
}
private static String decode(long i) {
StringBuilder sb = new StringBuilder();
while (i > 0) {
long digit = i % 10;
i /= 10;
if (digit == 0) {
sb.append((char) ('a' + i % 100 - 1));
i /= 100;
} else {
sb.append((char) ('a' + digit - 1));
}
}
return 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 | 1fe318339eb467659b0e6ae3987d5e4f | 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 jin=new Scanner(System.in);
int t=jin.nextInt();
while(t-->0){
int n=jin.nextInt();
String str=jin.next();
String ans="";
StringBuilder res=new StringBuilder(ans);
for(int i=n-1;i>=0;i--){
char ch=str.charAt(i);
if(ch!='0'){
res.append(""+((char)(ch+'a'-'1')));
}else{
String temp=""+str.charAt(i-2);
temp+=str.charAt(i-1);
i-=2;
int letval=Integer.parseInt(temp);
char letter=(char)(letval+'a'-1);
res.append(letter);
}
}res=res.reverse();
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 | 0e3fdbe2ab4f445f4f7c342f32ac9b89 | 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 sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for(int i=0;i<n;i++){
int l= sc.nextInt();
sc.nextLine();
String a= sc.nextLine();
String[] num;
num = a.split("");
int j=0;
StringBuilder ans= new StringBuilder();
String[] num1 = new String[l];
for(int w=0;w<l;w++){
num1[w]=num[l-1-w];
}
while(j<l){
int t=Integer.parseInt(num1[j]);
if(t!=0){
char c = (char)(t+96);
ans.append(c);
j++;
}
else{
String t2=num1[j+1];
String t3=num1[j+2];
String t4=t3+t2;
int y=Integer.parseInt(t4);
char c= (char)(y+96);
ans.append(c);
j=j+3;
}
}
StringBuilder ww = new StringBuilder();
ww.append(ans);
ww.reverse();
System.out.println(ww);
}
}
} | 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 | 9f324f6afef97b206099e082f8261435 | 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 scr = new Scanner(System.in);
int t = Integer.parseInt(scr.nextLine());
while(t > 0) {
int n = Integer.parseInt(scr.nextLine());
char[] s = scr.nextLine().toCharArray();
String ch = "abcdefghijklmnopqrstuvwxyz";
StringBuilder ans = new StringBuilder("");
for(int i = n-1;i >= 0;i--) {
int ind = 0;
if(s[i] == '0') {
i--;
ind = Integer.parseInt(String.valueOf(s[i]));
i--;
ind += Integer.parseInt(String.valueOf(s[i])) * 10;
}else {
ind = Integer.parseInt(String.valueOf(s[i]));
}
ans.insert(0,ch.charAt(ind-1));
}
System.out.println(ans);
t--;
}
if(scr != null)scr.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 | 2108ba6ad933c88ceae03cadc3a27e55 | 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();
sc.nextLine();
String s = sc.nextLine();
String ans = "";
n = n-1;
while(n>=0) {
if(s.charAt(n)=='0') {
int x = Integer.parseInt(""+ s.charAt(n-2) + s.charAt(n-1));
ans = (char)(96+x) + ans;
n = n-3;
} else {
ans = (char)(96+Integer.parseInt(""+s.charAt(n))) + ans;
n--;
}
}
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 | e057f75090aa80c9fb2d1998c7659e61 | 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 com.company;
import java.io.*;
import java.util.*;
public class Main{
static final Random random = new Random();
static boolean[] primecheck;
static ArrayList<Integer>[] adj;
static int[] vis;
static int[] parent;
static int[] rank;
static int[] fact;
static int[] invFact;
static int[] ft;
static int mod = (int)1e9 + 7;
public static void main(String[] args) throws IOException {
// FileReader f = new FileReader("C:\\Users\\Downloads" +
// "\\watering_well_chapter_2_input.txt");
OutputStream outputStream = System.out;
FastReader in = new FastReader();
// Reader in = new Reader();
PrintWriter out = new PrintWriter(outputStream);
// PROBLEM solver = new PROBLEM();
int t = 1;
t = in.ni();
for (int i = 0; i < t; i++) {
// out.print("Case #" + (i+1) + ": ");
// solver.solve(in, out);
PROBLEM.solve(in, out);
}
out.close();
}
static class PROBLEM {
public static void solve(FastReader in, PrintWriter out) throws IOException {
int n = in.ni();
char[] c = in.nline().toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
// out.println("enter i="+i);
if(c[i] == '0') continue;
int cur = 0;
if(c[i]>'2') cur = c[i]-'0';
else if(i<n-2 && c[i+2] == '0'){
if(i<n-3) {
if(c[i+3] != '0') {
cur = (c[i] - '0') * 10 + (c[i + 1] - '0');
i++;
}else cur = (c[i]-'0');
}else{
cur = (c[i] - '0') * 10 + (c[i + 1] - '0');
i++;
}
}else cur = (c[i]-'0');
char ch = (char)(cur+'a'-1);
// out.println("i="+i+" ch="+ch);
sb.append(ch);
}
out.println(sb);
}
}
static long ans = 0;
static int[] w, b;
static void dfs(int i, int p, char[] c){
vis[i] = 1;
if(c[i] == 'B') b[i] = 1;
else w[i] = 1;
for(int j : adj[i]){
if(j == p) continue;
if(vis[j] == 0){
dfs(j, i, c);
w[i] += w[j];
b[i] += b[j];
}
}
if(w[i] == b[i]){
ans++;
}
}
static int findLower(int[] a, int x){
int l = 0, r = a.length-1;
while(l<=r){
int mid = l + (r-l)/2;
if(a[mid]>=x) r = mid-1;
else l = mid+1;
}
return l;
}
static int findHigher(int[] a, int x){
int l = 0, r = a.length-1;
while(l<=r){
int mid = l + (r-l)/2;
if(a[mid]<=x) l = mid+1;
else r = mid-1;
}
return r;
}
static void graph(int n, int e, FastReader in) throws IOException {
adj = new ArrayList[n+1];
vis = new int[n+1];
for (int i = 0; i < n + 1; i++){
adj[i] = new ArrayList<>();
}
for (int i = 0; i < e; i++) {
int a = in.ni(), b = in.ni();
adj[a].add(b);
adj[b].add(a);
}
}
static int[] dx = {0, 0, 1, -1, 0, 0}, dy = {1, -1, 0, 0, 0, 0}, dz = {0, 0, 0, 0, 1, -1};
static int lower_bound(int array[], int key) {
int index = Arrays.binarySearch(array, key);
// If key is not present in the array
if (index < 0) {
// Index specify the position of the key
// when inserted in the sorted array
// so the element currently present at
// this position will be the lower bound
return Math.abs(index) - 1;
}
// If key is present in the array
// we move leftwards to find its first occurrence
else {
// Decrement the index to find the first
// occurrence of the key
// while (index > 0) {
//
// // If previous value is same
// if (array[index - 1] == key)
// index--;
//
// // Previous value is different which means
// // current index is the first occurrence of
// // the key
// else
// return index;
// }
return index;
}
}
static int upper_bound(int arr[], int key)
{
int index = Arrays.binarySearch(arr, key);
int n = arr.length;
// If key is not present in the array
if (index < 0) {
// Index specify the position of the key
// when inserted in the sorted array
// so the element currently present at
// this position will be the upper bound
return Math.abs(index) - 1;
}
// If key is present in the array
// we move rightwards to find next greater value
else {
// Increment the index until value is equal to
// key
// while (index < n) {
//
// // If current value is same
// if (arr[index] == key)
// index++;
//
// // Current value is different which means
// // it is the greater than the key
// else {
// return index;
// }
// }
return index;
}
}
static int getKthElement(int k){
int l = 0, r = ft.length-1, el = Integer.MAX_VALUE;
while(l <= r){
int mid = l+r>>1;
if(sumFenwick(ft, mid) >= k){
el = Math.min(el, mid);
r = mid-1;
}else l = mid+1;
}
return el;
}
static int rangeFenwick(int[] ft, int i, int j){
return sumFenwick(ft, j) - sumFenwick(ft, i);
}
static int sumFenwick(int[] ft, int i){
int sum = 0;
for(; i>0; i&=~(i&-i)) sum+=ft[i];
return sum;
}
static void addFenwick(int[] ft, int i, int x){
int n = ft.length;
for(; i<n; i+=i&-i) ft[i] += x;
}
static void combi(){
fact = new int[200001]; fact[0] = 1;
invFact = new int[200001]; invFact[0] = 1;
for (int i = 1; i < fact.length; i++) {
fact[i] = (int)(((long)fact[i-1]%mod * i%mod) % mod);
invFact[i] = (int)fast_pow(fact[i], mod-2);
}
}
static int nCk(int n, int k){
return (int)((long)fact[n] * invFact[k]%mod * invFact[n-k]%mod)%mod;
}
static String reverse(String s){
char[] ch = s.toCharArray();
for (int j = 0; j < ch.length / 2; j++) {
char temp = ch[j];
ch[j] = ch[ch.length-j-1];
ch[ch.length-j-1] = temp;
}
return String.valueOf(ch);
}
static int[][] matrixMul(int[][] a, int[][] m){
if(a[0].length == m.length) {
int[][] b = new int[a.length][m.length];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m.length; j++) {
int sum = 0;
for (int k = 0; k < m.length; k++) {
sum += m[i][k] * m[k][j];
}
b[i][j] = sum;
}
}
return b;
}
return null;
}
// static void dfs(int i, int d){
// vis[i] = 1;
// for(int j : adj[i]){
// if (vis[j] == 0) dfs(j, d+1);
// }
// }
static int find(int u){
if(u == parent[u]) return u;
return parent[u] = find(parent[u]);
}
static void union(int u, int v){
int a = find(u), b = find(v);
if(a == b) return;
if(rank[a] > rank[b]) parent[b] = a;
else if(rank[a] < rank[b]) parent[a] = b;
else{
parent[b] = a;
rank[a]++;
}
}
static void dsu(int n){
parent = new int[n];
rank = new int[n];
for (int i = 0; i < parent.length; i++) {
parent[i] = i;
rank[i] = 1;
}
}
static boolean isPalindrome(char[] s){
boolean b = true;
for (int i = 0; i < s.length / 2; i++) {
if(s[i] != s[s.length-1-i]){
b = false;
break;
}
}
return b;
}
static void yn(boolean b, PrintWriter out){
if(b) out.println("YES");
else out.println("NO");
}
static void pa(int[] a, PrintWriter out){
for (int j : a) out.print(j + " ");
out.println();
}
static void pa(long[] a, PrintWriter out){
for (long j : a) out.print(j + " ");
out.println();
}
public static void sortByColumn(int arr[][], int col)
{
// Using built-in sort function Arrays.sort
Arrays.sort(arr, new Comparator<>() {
@Override
// Compare values according to columns
public int compare(final int[] entry1,
final int[] entry2) {
// To sort in descending order revert
// the '>' Operator
if (entry1[col] > entry2[col])
return 1;
else
return -1;
}
}); // End of function call sort().
}
static boolean isPoT(long n){
return ((n&(n-1)) == 0);
}
static long sigmaK(long k){
return (k*(k+1))/2;
}
static void swap(int[] a, int l, int r) {
int temp = a[l];
a[l] = a[r];
a[r] = temp;
}
static int binarySearch(int[] a, int l, int r, int x){
if(r>=l){
int mid = l + (r-l)/2;
if(a[mid] == x) return mid;
if(a[mid] > x) return binarySearch(a, l, mid-1, x);
else return binarySearch(a,mid+1, r, x);
}
return -1;
}
static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static long lcm(long a, long b){
return (a / gcd(a, b)) * b;
}
static int ceil(int a, int b){
return (a+b-1)/b;
}
static long ceil(long a, long b){
return (a+b-1)/b;
}
static boolean isSquare(double a) {
boolean isSq = false;
double b = Math.sqrt(a);
double c = Math.sqrt(a) - Math.floor(b);
if (c == 0) isSq = true;
return isSq;
}
static long fast_pow(long a, long b) { //Jeel bhai OP
if(b == 0)
return 1L;
long val = fast_pow(a, b / 2);
if(b % 2 == 0)
return val * val % mod;
else
return val * val % mod * a % mod;
}
// 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 o){
//
// int ans = Integer.compare(x, o.x);
// if(o.x == x) ans = Integer.compare(y, o.y);
//
// return ans;
//
//// int ans = Integer.compare(y, o.y);
//// if(o.y == y) ans = Integer.compare(x, o.x);
////
//// return ans;
// }
// }
static class Tuple implements Comparable<Tuple>{
int x, y, z;
Tuple(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
public int compareTo(Tuple o){
int ans = Integer.compare(x, o.x);
if(o.x == x) ans = Integer.compare(y, o.y);
return ans;
}
}
public static class Pair<U extends Comparable<U>, V extends Comparable<V>,
W extends Comparable<W>> implements Comparable<Pair<U, V, W>> {
public U x;
public V y;
public W z;
public Pair(U x, V y, W z) {
this.x = x;
this.y = y;
this.z = z;
}
public int hashCode() {
return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
}
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Pair<U, V, W> p = (Pair<U, V, W>) o;
return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
}
public int compareToX(Pair<U, V, W> b) {
int cmpU = x.compareTo(b.x);
return cmpU != 0 ? cmpU : y.compareTo(b.y);
}
public int compareToY(Pair<U, V, W> b) {
int cmpU = b.y.compareTo(y); // sorts acc. to y in desc. order........
return cmpU != 0 ? cmpU : x.compareTo(b.x); // y.compareTo(b.y) -> for ascending
}
public String toString() {
return String.format("(%s, %s)", x.toString(), y.toString());
}
@Override
public int compareTo(Pair<U, V, W> o) {
return 0;
}
}
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 nline(int n) throws IOException {
byte[] buf = new byte[n+1]; // 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 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 int[] ra(int size) throws IOException {
int[] array = new int[size];
for (int i = 0; i < size; i++) array[i] = ni();
return array;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(FileReader f) {
br = new BufferedReader(f);
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
long nl() {
return Long.parseLong(next());
}
double nd() {
return Double.parseDouble(next());
}
char nc() {
return next().charAt(0);
}
boolean nb() {
return !(ni() == 0);
}
// boolean nextBoolean(){return Boolean.parseBoolean(next());}
String nline() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] ra(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) array[i] = ni();
return array;
}
public long[] ral(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) array[i] = nl();
return array;
}
}
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
public static void Sieve(int n) {
Arrays.fill(primecheck, true);
primecheck[0] = false;
primecheck[1] = false;
for (int i = 2; i * i < n + 1; i++) {
if (primecheck[i]) {
for (int j = i * 2; j < n + 1; j += i) {
primecheck[j] = 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 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 | f6697761056ba7822208ae773f274eec | 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 decode {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
String str="";
while(t-->0)
{
int n=sc.nextInt();
String s=sc.next();
for(int i=n-1;i>=0;i--)
{
char ch=s.charAt(i);
if(ch!='0')
{
int c=Character.getNumericValue(ch);
str=(char)(c+96)+str;
}
else
{
char c1=s.charAt(i-2);
char c2=s.charAt(i-1);
String s1=c1+""+c2;
// System.out.println(s1);
int c=Integer.valueOf(s1);
i=i-2;
str=(char)(c+96)+str;
}
}
System.out.println(str);
str="";
}
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 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 | 4e88d6d4371848822397182ac36532af | 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.IOException;
public class Solution {
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 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 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);
}
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 static void main(String[] args)
throws IOException {
Reader s = new Reader();
int q = s.nextInt();
StringBuilder sb = new StringBuilder();
while (q-- > 0) {
int n = s.nextInt();
String str = s.readLine();
StringBuilder ans = new StringBuilder();
for (int i = n - 1; i >= 0; i--) {
if (str.charAt(i) == '0') {
char c = (char) ('a' + (str.charAt(i - 2) - 48) * 10 + (str.charAt(i - 1) - 48) - 1);
ans.insert(0, c);
i -= 2;
} else {
ans.insert(0, (char) ('a' + (str.charAt(i) - 48) - 1));
}
}
sb.append(ans).append('\n');
}
System.out.append(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 | b4349b8883560647e70e263a81035635 | 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) {
try {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-->0) {
int n=sc.nextInt();
String s = sc.next();
String a = "";
String res = "";
for(int i=0;i<n;i++){
char ch = s.charAt(i);
// System.out.println(ch);
if(ch!='0')
a+=ch;
else if( i!=n-1 && s.charAt(i+1)=='0') {
a+=ch;
continue;
}
else {
char ch1 = a.charAt(a.length()-2);
char ch2 = a.charAt(a.length()-1);
String l2 = ch1+""+ch2;
int num = Integer.parseInt(l2);
char c = (char) (96+num);
int j=0;
while(j<a.length()-2){
char c1 = (char)(96+Integer.parseInt(a.charAt(j)+""));
res+=c1;
j++;
}
a="";
res+=c;
}
}
int j=0;
while(j<a.length()){
char c1 = (char)(96+Integer.parseInt(a.charAt(j)+""));
// System.out.println(c1);
res+=c1;
j++;
}
System.out.println(res);
}
}
catch (Exception e){
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 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 | e6c175f109e87473cc6387719db4d64a | 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 p=sc.nextInt();
while(p-->0){
int l=sc.nextInt();
String res=sc.next();
String dec="";
int i=0;
for(i=res.length()-1;i>=0;i--){
char ch1=res.charAt(i);
if(ch1!='0'){
dec+=(char)(ch1-'0'+96);
}
else{
i--;
char ch3=res.charAt(i);
if(i-1<res.length()){
String ch2=""+res.charAt(i-1)+ch3;
int t=Integer.parseInt(ch2);
dec+=(char)(t+96);
i--;
}
}
}
System.out.println(new StringBuilder(dec).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 | 36de648f85c6081b9809c6c051d0d415 | 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 b {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int ci = 0; ci < t; ci++) {
StringBuilder sb = new StringBuilder();
in.next();
String str = in.next();
for (int i = str.length() - 1; i >= 0; i--) {
char c = str.charAt(i);
if (c == '0') {
int ten = str.charAt(i - 2) - '0';
int one = str.charAt(i - 1) - '0';
sb.append((char) ('a' + one + ten * 10 - 1));
i -= 2;
} else {
sb.append((char) ('a' + c - '0' - 1));
}
}
sb.reverse();
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 | 9e163713b8611e5c1869f03d64ed626b | 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 SolutionB{
static String decodeString(int n,String number){
String ans="";
for(int i=n-1;i>=0;i--){
int last=number.charAt(i)-'0';
if(last!=0){
ans=(char)(last+96)+ans;
}else{
ans=(char)(Integer.parseInt(number.substring(i-2,i))+96)+ans;
i-=2;
}
}
return ans;
}
public static void main(String args[]){
Scanner input=new Scanner(System.in);
int n=Integer.parseInt(input.nextLine());
for(int i=0;i<n;i++){
System.out.println(decodeString(Integer.parseInt(input.nextLine()),input.nextLine()));
}
}
} | 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 | c6df449f183b61ca90f729da1a5e3625 | 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.HashMap;
import java.util.Scanner;
public class ProblemB {
public static void main(String[] args) {
// TODO Auto-generated method stub
int freq[] = {1,2,3,4,5,6,7,8,9,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260};
char c[] = {'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'};
HashMap<Integer,Character> map = new HashMap<>();
for(int i=0;i<26;i++) {
map.put(freq[i],c[i]);
}
Scanner sc = new Scanner(System.in);
long t = sc.nextLong();
while(t-->0) {
int n = sc.nextInt();
String ans ="";
String inp = sc.next();
for(int i=0;i<n;i++) {
if(i+2<n) {
if(inp.charAt(i+2)=='0' && (i+3>=n||inp.charAt(i+3)!='0')) {
int key = (inp.charAt(i)-'0')*100+(inp.charAt(i+1)-'0')*10;
ans+=map.get(key);
i=i+2;
}
else {
ans+=map.get(inp.charAt(i)-'0');
}
}
else {
ans+=map.get(inp.charAt(i)-'0');
}
}
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 | b9618b45b740ed3d10500b7331fd3820 | 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 EncodeAscii {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int testCases=sc.nextInt();
ArrayList<String> decoded=new ArrayList<>();
for(int iterator=0;iterator<testCases;iterator++){
int size=sc.nextInt();
String number=sc.next();
String result="";
for(int iteratorTwo=number.length()-1;iteratorTwo>=0;){
int index = number.charAt(iteratorTwo)-'0';
if(index==0){
String newNumber=""+number.charAt(iteratorTwo-2)+number.charAt(iteratorTwo-1);
index=Integer.parseInt(newNumber);
iteratorTwo-=2;
}
result+=(char)(index + 96);
iteratorTwo--;
}
String appendString="";
for(int iteratorTwo=result.length()-1;iteratorTwo>=0;iteratorTwo--){
appendString+=result.charAt(iteratorTwo);
}
decoded.add(appendString);
}
for(int iterator=0;iterator<testCases;iterator++){
System.out.println(decoded.get(iterator));
}
}
}
| 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 | 8115cf65a0046032479f13d299540ee9 | 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 Musor {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int b = s.nextInt();
for (int k = 0; k < b ; k++) {
int n = s.nextInt();
s.nextLine();
String rt = s.nextLine();
int[] arr = new int[n];
char[] ch = rt.toCharArray();
String str = "";
for (int i = 0; i < n; i++) {
arr[i] = ch[i] - 48;
}
for (int i = 0; i < arr.length; i++) {
if (arr.length - 2 <= i) {
str += (char) (arr[i] + 96);
} else if (arr[i + 2] != 0) {
str += (char) (arr[i] + 96);
} else if (arr[i + 2] == 0) {
if (ch.length - i >= 4) {
if (arr[i + 3] == 0) {
str += (char) (arr[i] + 96);
} else {
str += (char) (arr[i] * 10 + 96 + arr[i + 1]);
i += 2;
}
} else {
str += (char) (arr[i] * 10 + 96 + arr[i + 1]);
i += 2;
}
}
}
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 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 | 5e30ecf9fbc3e7d2c66b94972668be21 | 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;
/**
*
* @author lenovo
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
MyScanner input=new MyScanner();
char characters[]=new char[27];
char myChar='a';
for(int it=0;it<characters.length;it++)
{
characters[it]=myChar;
myChar++;
}
int test=input.nextInt();
while(test--!=0)
{
int length=input.nextInt();
String myNumber=input.next();
String answer="";
char[] digits=myNumber.toCharArray();
int n=digits.length;
for(int i=n-1;i>=0;i--)
{
if(digits[i]=='0')
{
int second=digits[i-1]-'0';
int first=digits[i-2]-'0';
int number=first*10+second;
answer=characters[number-1]+answer;
i=i-2;
}
else
{
int number=digits[i]-'0';
answer=characters[number-1]+answer;
}
}
System.out.println(answer);
}
}
}
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 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 | 09095303c380ec5e4cb3e1b4e1580a9f | 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 Contest {
public static void solve()
{
Scanner input=new Scanner (System.in);
int t=input.nextInt();
while(t-->0)
{
StringBuilder st=new StringBuilder();
int n=input.nextInt();
String alpha="aabcdefghijklmnopqrstuvwxyz";
String s=input.next();
int sum=0;
for(int i=s.length()-1;i>=0;)
{
if(s.charAt(i)=='0')
{
sum+=s.charAt(i-1)-48;
sum+=(s.charAt(i-2)-48)*10;
st.append(alpha.charAt(sum));
sum=0;
i-=3;
}
else
{
st.append(alpha.charAt(s.charAt(i)-48));
i--;
}
}
System.out.println(st.reverse());
}
}
public static void main(String[] args) {
solve();
//عمداانييي
//في مهندسين كتير بس مفيش نسور كود خالص
}} | 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 | 7cd37c6fe6b43618d34260472dba110a | 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 codeforce {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int m =in.nextInt();//length of words
String s = in.next();
StringBuilder a = new StringBuilder();
for (int j = s.length()-1; j >= 0 ; j--) {
if(s.charAt(j) == '0'){
a.append((char)(Integer.parseInt(s.substring(j-2, j)) + 96));
j-= 2;
}
else{
a.append((char)(Integer.parseInt(String.valueOf(s.charAt(j))) + 96));
}
}
System.out.println(a.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 | 4f7bf9231667873f23c379faa347c38d | 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 B {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
for(;t>0;t--){
int i=sc.nextInt()-1;
String ajam=sc.next();
ArrayDeque<Character> olee=new ArrayDeque();
while(i>=0){
if(ajam.charAt(i)=='0'){
i--;
String num=""+ajam.charAt(i-1)+ajam.charAt(i);
int x=Integer.parseInt(num);
olee.addLast((char)(x+96));
i-=2;
}else{
String num=""+ajam.charAt(i);
int x=Integer.parseInt(num);
// System.out.println(x);
olee.addLast((char)(x+96));
i--;
}
}
StringBuilder out= new StringBuilder();
while(!olee.isEmpty()){
out.append(olee.pollLast());
}
System.out.println(out);
}
}
}
| 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 | 99714e2f370a04971ca296d768259941 | 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 {
// For fast input output
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
try {br = new BufferedReader(new InputStreamReader(System.in));}
catch (Exception e) {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;
}
}
// end of fast i/o code
public static void main(String[] args) {
FastReader reader = new FastReader();
int T = reader.nextInt();
while (T-- > 0) {
int n = reader.nextInt();
// int m = reader.nextInt();
// int x = reader.nextInt();
// int y = reader.nextInt();
String t = reader.next();
int zeros=0;
for (int i = n-1; i >=1; i--) {
char c=t.charAt(i);
if (c=='0'){
if (t.charAt(i-1)=='0'){
i--;
zeros++;
}
else zeros++;
}
}
int ssize=n-(zeros*2);
int ssize1=ssize;
char[] s=new char[ssize];
for (int i = n-1; i >=0 ; i--) {
char c=t.charAt(i);
if (c=='0'){
i=i-2;
String temp=t.substring(i, i+2);
int t1=Integer.parseInt(temp);
s[--ssize]=(char) ('a'+(t1-1));
}
else {
String temp=t.substring(i, i+1);
int t1=Integer.parseInt(temp);
s[--ssize]=(char) ('a'+(t1-1));
}
}
String s1=new String(s);
System.out.println(s1);
}
}
public static int combination(int n, int r)
{
return factorial(n) / (factorial(r) * factorial(n - r));
}
public static int factorial(int n)
{
if (n == 0)
return 1;
return n*factorial(n-1);
}
public static boolean isint(double n){
double n1= Math.floor(n);
return n1 == n;
}
public static int min_length_bet_same_elements(int [] a, int n){
Map<Integer, Integer> map=new HashMap<>();
int maxL=Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
if(map.containsKey(a[i])){
int prev=map.get(a[i]);
prev+=(n-i);
maxL=Math.max(prev, maxL);
}
map.put(a[i], i);
}
if (maxL==Integer.MIN_VALUE) return -1;
else return (n-maxL);
}
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, 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 | e414b855d8dd8f5c06689e00aa1612a6 | 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 | // Author : Shadman Shariar //
// Email : [email protected] //
import java.io.*; import java.util.*;
import java.time.*; import java.lang.Math.*;
import java.io.BufferedReader; import java.io.IOException;
import java.math.BigInteger; import java.text.DecimalFormat;
import java.io.InputStreamReader; import java.io.PrintWriter;
import java.util.function.Supplier;import java.io.Closeable;
import java.util.regex.Pattern;import java.util.regex.Matcher;
import java.util.stream.*;
import javax.imageio.stream.IIOByteBuffer;
import static java.lang.System.exit;
import java.nio.charset.Charset; import java.security.KeyStore.Entry;
public class Main {
public static Main obj = new Main();
private static final Integer Null = null;
public static final long N = (long)(1000000001);
public static final long Bigmod = 1_000_000_007;
public static final String Vowels = "aeiouAEIOU";
public static final Random random = new Random();
public static int [] dx = {-1, 1, 0, 0, -1, -1, 1, 1};
public static int [] dy = {0, 0, -1, 1, -1, 1, -1, 1};
public static int [] dp1 = new int [10];
public static int [][] dp2 = new int[10][10];
public static final long bigmod = (long)(Math.pow(10,9)+7);
public static final String spliter1 = "\\s+", spliter2 = "[ ]+";
public static FastReader fr = new FastReader();
public static Scanner input = new Scanner(System.in);
public static PrintWriter out = new PrintWriter(System.out);
public static DecimalFormat df = new DecimalFormat(".000");
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main (String[]args) throws Exception{Scanner input=new Scanner(System.in);
//===========================================================================================//
//Vector vc = new Vector();
//BigInteger bi = new BigInteger("1000");
//StringBuilder sb = new StringBuilder();
//StringBuffer sbf = new StringBuffer();
//StringTokenizer st = new StringTokenizer("string",spliter1);
//ArrayList<Integer> al= new ArrayList<Integer>();
//LinkedList<Integer> ll= new LinkedList<Integer>();
//Stack <Integer> stk = new Stack <Integer>();
//Queue <Integer> q = new LinkedList<Integer>();
//ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
//PriorityQueue <Integer> pq = new PriorityQueue<Integer>();
//PriorityQueue <Integer> pqr = new PriorityQueue<Integer>(Comparator.reverseOrder());
//HashSet<Integer> hs = new HashSet<Integer>();
//LinkedHashSet<Integer> lhs = new LinkedHashSet<Integer>();
//TreeSet<Integer> ts = new TreeSet<Integer>();
//TreeSet<Integer> tsr = new TreeSet<Integer>(Comparator.reverseOrder());
//Hashtable<Integer,Integer> ht = new Hashtable<Integer,Integer>();
//HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
//LinkedHashMap<Integer,Integer> lhm = new LinkedHashMap<Integer,Integer>();
//TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>();
//TreeMap<Integer,Integer> tmr = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
//ArrayList<ArrayList<Integer>> al2= new ArrayList<ArrayList<Integer>>();
//LinkedList<LinkedList<Integer>> ll2= new LinkedList<LinkedList<Integer>>();
//LinkedList<Integer> adj[] = new LinkedList[1000];
//ArrayList<Integer> adj2[] = new ArrayList[1000];
//HashSet<Integer> hsj[] = new HashSet[1000];
//HashMap<Integer,Integer> hmj[] = new HashMap[1000];
//ArrayList<int[]> aa = new ArrayList<int[]>();
//LinkedList<long[]> al = new LinkedList<long[]>();
//Arrays.sort(array, Comparator.comparingInt(o -> o[0]));
//SortedSet< Integer > ss = new TreeSet<>( (i, j) -> i > j ? 1 : -1 );
//SortedMap< Integer, Integer > sm = new TreeMap<>( (i, j) -> i > j ? 1 : -1 );
//===========================================================================================//
//long start = System.currentTimeMillis();
// Bitmask -----------------------------------
// Check Bit - (number&(1<<pos)) -> 0/1 bit |
// Set Bit - number = (number|(1<<pos)) |
// Unset Bit - number = (number&(~(1<<pos))) |
// inverse toggle - number = number^(1<<pos) |
//--------------------------------------------
int tc = 1;
tc = input.nextInt();
for (int tt = 1; tt <= tc; tt++) {
int n = input.nextInt();
String s = input.next();
Stack<Character> stk = new Stack<Character>();
for (int i = 0; i < s.length(); i++) {
stk.push(s.charAt(i));
}
// debug(stk);
StringBuilder sb = new StringBuilder();
while(!stk.isEmpty()) {
if(stk.peek()=='0') {
stk.pop();
String s1 = stk.pop()+"";
String s2 = stk.pop()+"";
int tmp = Integer.parseInt(s2+s1);
char ch = (char)(96+tmp);
sb.append(ch);
}
else {
String s1 = stk.pop()+"";
int tmp = Integer.parseInt(s1);
char ch = (char)(96+tmp);
sb.append(ch);
}
// debug(stk);
}
System.out.println(sb.reverse());
}
//long end = System.currentTimeMillis();
//System.out.println("Time : "+((end-start)/1000));
//===========================================================================================//
out.flush();
out.close();
input.close();
System.exit(0);
}
//===========================================================================================//
//-------->> Temporary Method Starts Here <<--------//
//-------->> Temporary Method Ends Here <<--------//
//===========================================================================================//
public static void bdfs(char[][] grid, int i, int j) {
if(i<0||j<0||i>=grid.length||j>=grid[i].length||grid[i][j]=='0')return;
grid[i][j] = '0';bdfs(grid, i+1, j);bdfs(grid, i-1, j);bdfs(grid, i, j+1);
bdfs(grid, i, j-1); return;}
public static class pair { int first, second;
public pair(int first, int second)
{ this.first = first; this.second = second;}}
public static void debug(Object... obj){System.err.println(Arrays.deepToString(obj));}
public static void swap(int a[], int i, int j) {
a[i] ^= a[j];a[j] ^= a[i];a[i] ^= a[j];}
public static void swap(long a[], int i, int j) {
a[i] ^= a[j];a[j] ^= a[i];a[i] ^= a[j];}
public static void sort(int[] a) {ArrayList<Integer> l=new ArrayList<>();
for(int i:a)l.add(i);Collections.sort(l);for(int i=0; i<a.length;i++)a[i]=l.get(i);}
public static long add(long a, long b) {return (a+b)%Bigmod;}
public static long sub(long a, long b) {return ((a-b)%Bigmod+Bigmod)%Bigmod;}
public static long mul(long a, long b) {return (a*b)%Bigmod;}
public static long exp(long base,long exp){if(exp==0)return 1;long half=exp(base,exp/2);
if (exp%2==0) return mul(half, half);return mul(half, mul(half, base));}
public static long lcm(long a,long b){return (a/gcd(a,b))*b;}
public static long gcd(long a,long b){if(a==0)return b;return gcd(b%a,a);}
public static long nPr(long n,long r){return factorial(n)/factorial(n-r);}
public static long nCr(long n,long r){return factorial(n)/(factorial(r)*factorial(n-r));}
public static long factorial(long n){return (n==1||n==0)?1:n*factorial(n-1);}
public static long countsubstr(String str){long n=str.length();return n*(n+1)/2;}
public static long fastpower(long a,long b,long n) {long res=1;while(b>0){if((b&1)!=0)
{res=(res*a%n)%n;}a=(a%n*a%n)%n;b=b>>1;}return res;}
public static void subsequences(String s,String ans){if(s.length()==0){ss.
add(ans);return;}subsequences(s.substring(1),ans+s.charAt(0));subsequences
(s.substring(1),ans);}public static List<String>ss=new ArrayList<>();
public static boolean perfectsquare(long x){if(x>=0)
{long sr=(long)(Math.sqrt(x));return((sr*sr)==x);}return false;}
public static boolean perfectcube(long N){int cube;int c=0;for(int i=0;i<=N;i++){cube=i*i*i;
if(cube==N){c=1;break;}else if (cube>N){c=0;break;}}if(c==1)return true;else return false;}
public static boolean[] sieveOfEratosthenes(int n){boolean prime[]=new boolean[n+1];
for (int i = 0; i <= n; i++)prime[i] = true;for (int p = 2; p * p <= n; p++){
if(prime[p]==true){for(int i=p*p;i<=n;i+=p)prime[i]=false;}}prime[1]=false;return prime;}
public static int binarysearch(int arr[],int l,int r,int x)
{if (r >= l){int mid = l + (r - l) / 2;if (arr[mid]==x)return mid;if(arr[mid]>x)return
binarysearch(arr, l, mid - 1, x);return binarysearch(arr, mid + 1, r, x);}return -1;}
public static void rangeofprime(int a,int b){int i, j, flag;for (i = a; i <= b; i++)
{if (i == 1 || i == 0)continue;flag = 1;for (j = 2; j <= i / 2; ++j) {if (i % j == 0)
{flag = 0;break;}}if (flag == 1)System.out.println(i);}}
public static boolean isprime(long n){if(n<=1)return false;else if(n==2)return true;else if
(n%2==0)return false;for(long i=3;i<=Math.sqrt(n);i+=2){if(n%i==0)return false;}return true;}
public static void rufflesort(int[]a){int n=a.length;for(int i=0;i<n;i++){
int oi=random.nextInt(n),temp=a[oi];a[oi]=a[i]; a[i]=temp;}Arrays.sort(a);}
public static int pit(int n){int res=1;for(int i=2;i<n;i++)if(gcd(i,n)==1)res++;return res;}
//===========================================================================================//
public static class Node{
int data ; Node left, right;
public Node (int data) {
this.data = data;
}
}
public static Node createTree() {
Node root = null;
System.out.println("data : ");
int data = input.nextInt();
if(data == -1) return null;
root = new Node(data);
System.out.println("left : " + data);
root.left = createTree();
System.out.println("right :"+ data);
root.right = createTree();
return root;
}
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());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayL(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
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 | 656d7270173153560087c3f12267759d | 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 | // Author : Shadman Shariar //
// Email : [email protected] //
import java.io.*; import java.util.*;
import java.time.*; import java.lang.Math.*;
import java.io.BufferedReader; import java.io.IOException;
import java.math.BigInteger; import java.text.DecimalFormat;
import java.io.InputStreamReader; import java.io.PrintWriter;
import java.util.function.Supplier;import java.io.Closeable;
import java.util.regex.Pattern;import java.util.regex.Matcher;
import java.util.stream.*;import static java.lang.System.exit;
import java.nio.charset.Charset; import java.security.KeyStore.Entry;
public class Main {
public static Main obj = new Main();
private static final Integer Null = null;
public static final long N = (long)(1000000001);
public static final long Bigmod = 1_000_000_007;
public static final String Vowels = "aeiouAEIOU";
public static final Random random = new Random();
public static int [] dx = {-1, 1, 0, 0, -1, -1, 1, 1};
public static int [] dy = {0, 0, -1, 1, -1, 1, -1, 1};
public static int [] dp1 = new int [10];
public static int [][] dp2 = new int[10][10];
public static final long bigmod = (long)(Math.pow(10,9)+7);
public static final String spliter1 = "\\s+", spliter2 = "[ ]+";
public static FastReader fr = new FastReader();
public static Scanner input = new Scanner(System.in);
public static PrintWriter out = new PrintWriter(System.out);
public static DecimalFormat df = new DecimalFormat(".000");
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main (String[]args) throws Exception{Scanner input=new Scanner(System.in);
//===========================================================================================//
//Vector vc = new Vector();
//BigInteger bi = new BigInteger("1000");
//StringBuilder sb = new StringBuilder();
//StringBuffer sbf = new StringBuffer();
//StringTokenizer st = new StringTokenizer("string",spliter1);
//ArrayList<Integer> al= new ArrayList<Integer>();
//LinkedList<Integer> ll= new LinkedList<Integer>();
//Stack <Integer> stk = new Stack <Integer>();
//Queue <Integer> q = new LinkedList<Integer>();
//ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
//PriorityQueue <Integer> pq = new PriorityQueue<Integer>();
//PriorityQueue <Integer> pqr = new PriorityQueue<Integer>(Comparator.reverseOrder());
//HashSet<Integer> hs = new HashSet<Integer>();
//LinkedHashSet<Integer> lhs = new LinkedHashSet<Integer>();
//TreeSet<Integer> ts = new TreeSet<Integer>();
//TreeSet<Integer> tsr = new TreeSet<Integer>(Comparator.reverseOrder());
//Hashtable<Integer,Integer> ht = new Hashtable<Integer,Integer>();
//HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
//LinkedHashMap<Integer,Integer> lhm = new LinkedHashMap<Integer,Integer>();
//TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>();
//TreeMap<Integer,Integer> tmr = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
//ArrayList<ArrayList<Integer>> al2= new ArrayList<ArrayList<Integer>>();
//LinkedList<LinkedList<Integer>> ll2= new LinkedList<LinkedList<Integer>>();
//LinkedList<Integer> adj[] = new LinkedList[1000];
//ArrayList<Integer> adj2[] = new ArrayList[1000];
//HashSet<Integer> hsj[] = new HashSet[1000];
//HashMap<Integer,Integer> hmj[] = new HashMap[1000];
//ArrayList<int[]> aa = new ArrayList<int[]>();
//LinkedList<long[]> al = new LinkedList<long[]>();
//Arrays.sort(array, Comparator.comparingInt(o -> o[0]));
//SortedSet< Integer > ss = new TreeSet<>( (i, j) -> i > j ? 1 : -1 );
//SortedMap< Integer, Integer > sm = new TreeMap<>( (i, j) -> i > j ? 1 : -1 );
//===========================================================================================//
//long start = System.currentTimeMillis();
// Bitmask -----------------------------------
// Check Bit - (number&(1<<pos)) -> 0/1 bit |
// Set Bit - number = (number|(1<<pos)) |
// Unset Bit - number = (number&(~(1<<pos))) |
// inverse toggle - number = number^(1<<pos) |
//--------------------------------------------
int tc = 1;
tc = input.nextInt();
for (int tt = 1; tt <= tc; tt++) {
int n = input.nextInt();
String s = input.next();
StringBuilder sb = new StringBuilder();
Stack<Character> stk = new Stack<Character>();
for (int i = 0; i < s.length(); i++) {
stk.push(s.charAt(i));
}
while(!stk.isEmpty()) {
int tmp = stk.peek()-'0';
stk.pop();
if(tmp!=0) {
sb.append((char)(tmp-1+'a'));
}
else {
int s2 = stk.peek()-'0';
stk.pop();
int x = stk.peek()-'0';
stk.pop();
int y = x*10+s2;
sb.append((char)(y-1+'a'));
}
}
System.out.println(sb.reverse());
}
//long end = System.currentTimeMillis();
//System.out.println("Time : "+((end-start)/1000));
//===========================================================================================//
out.flush();
out.close();
input.close();
System.exit(0);
}
//===========================================================================================//
//-------->> Temporary Method Starts Here <<--------//
//-------->> Temporary Method Ends Here <<--------//
//===========================================================================================//
public static void bdfs(char[][] grid, int i, int j) {
if(i<0||j<0||i>=grid.length||j>=grid[i].length||grid[i][j]=='0')return;
grid[i][j] = '0';bdfs(grid, i+1, j);bdfs(grid, i-1, j);bdfs(grid, i, j+1);
bdfs(grid, i, j-1); return;}
public static class pair { int first, second;
public pair(int first, int second)
{ this.first = first; this.second = second;}}
public static void debug(Object... obj){System.err.println(Arrays.deepToString(obj));}
public static void swap(int a[], int i, int j) {
a[i] ^= a[j];a[j] ^= a[i];a[i] ^= a[j];}
public static void swap(long a[], int i, int j) {
a[i] ^= a[j];a[j] ^= a[i];a[i] ^= a[j];}
public static void sort(int[] a) {ArrayList<Integer> l=new ArrayList<>();
for(int i:a)l.add(i);Collections.sort(l);for(int i=0; i<a.length;i++)a[i]=l.get(i);}
public static long add(long a, long b) {return (a+b)%Bigmod;}
public static long sub(long a, long b) {return ((a-b)%Bigmod+Bigmod)%Bigmod;}
public static long mul(long a, long b) {return (a*b)%Bigmod;}
public static long exp(long base,long exp){if(exp==0)return 1;long half=exp(base,exp/2);
if (exp%2==0) return mul(half, half);return mul(half, mul(half, base));}
public static long lcm(long a,long b){return (a/gcd(a,b))*b;}
public static long gcd(long a,long b){if(a==0)return b;return gcd(b%a,a);}
public static long nPr(long n,long r){return factorial(n)/factorial(n-r);}
public static long nCr(long n,long r){return factorial(n)/(factorial(r)*factorial(n-r));}
public static long factorial(long n){return (n==1||n==0)?1:n*factorial(n-1);}
public static long countsubstr(String str){long n=str.length();return n*(n+1)/2;}
public static long fastpower(long a,long b,long n) {long res=1;while(b>0){if((b&1)!=0)
{res=(res*a%n)%n;}a=(a%n*a%n)%n;b=b>>1;}return res;}
public static void subsequences(String s,String ans){if(s.length()==0){ss.
add(ans);return;}subsequences(s.substring(1),ans+s.charAt(0));subsequences
(s.substring(1),ans);}public static List<String>ss=new ArrayList<>();
public static boolean perfectsquare(long x){if(x>=0)
{long sr=(long)(Math.sqrt(x));return((sr*sr)==x);}return false;}
public static boolean perfectcube(long N){int cube;int c=0;for(int i=0;i<=N;i++){cube=i*i*i;
if(cube==N){c=1;break;}else if (cube>N){c=0;break;}}if(c==1)return true;else return false;}
public static boolean[] sieveOfEratosthenes(int n){boolean prime[]=new boolean[n+1];
for (int i = 0; i <= n; i++)prime[i] = true;for (int p = 2; p * p <= n; p++){
if(prime[p]==true){for(int i=p*p;i<=n;i+=p)prime[i]=false;}}prime[1]=false;return prime;}
public static int binarysearch(int arr[],int l,int r,int x)
{if (r >= l){int mid = l + (r - l) / 2;if (arr[mid]==x)return mid;if(arr[mid]>x)return
binarysearch(arr, l, mid - 1, x);return binarysearch(arr, mid + 1, r, x);}return -1;}
public static void rangeofprime(int a,int b){int i, j, flag;for (i = a; i <= b; i++)
{if (i == 1 || i == 0)continue;flag = 1;for (j = 2; j <= i / 2; ++j) {if (i % j == 0)
{flag = 0;break;}}if (flag == 1)System.out.println(i);}}
public static boolean isprime(long n){if(n<=1)return false;else if(n==2)return true;else if
(n%2==0)return false;for(long i=3;i<=Math.sqrt(n);i+=2){if(n%i==0)return false;}return true;}
public static void rufflesort(int[]a){int n=a.length;for(int i=0;i<n;i++){
int oi=random.nextInt(n),temp=a[oi];a[oi]=a[i]; a[i]=temp;}Arrays.sort(a);}
public static int pit(int n){int res=1;for(int i=2;i<n;i++)if(gcd(i,n)==1)res++;return res;}
//===========================================================================================//
public static class Node{
int data ; Node left, right;
public Node (int data) {
this.data = data;
}
}
public static Node createTree() {
Node root = null;
System.out.println("data : ");
int data = input.nextInt();
if(data == -1) return null;
root = new Node(data);
System.out.println("left : " + data);
root.left = createTree();
System.out.println("right :"+ data);
root.right = createTree();
return root;
}
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());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayL(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
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 | 52ad1e68b549886bdff0cd25bb849d1f | 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 {
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){
int n = Integer.parseInt(br.readLine());
String s = br.readLine();
Stack<Character> st = new Stack<>();
for(int i=s.length()-1;i>=0;i--){
int x = s.charAt(i)-'0';
if(x==0){
x=(s.charAt(i-2)-'0')*10+s.charAt(i-1)-'0';
i-=2;
}
st.add((char)('a'+x-1));
}
StringBuffer sb = new StringBuffer();
while(!st.isEmpty()){
sb.append(st.pop());
}
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 | af2ec030e71f9d80203716326bf8d317 | 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();
while(t-->0){
int n = sc.nextInt();
String s = sc.next();
String alphabet = " abcdefghijklmnopqrstuvwxyz";
StringBuilder res = new StringBuilder("");
for(int i=0;i<n;i++){
int x = Integer.parseInt(String.valueOf(s.charAt(i)));
if(x>2){
res.append(String.valueOf(alphabet.charAt(x)));
}
else{
if(i>=n-2){
res.append(String.valueOf(alphabet.charAt(x)));
}
else if(i<n-3){
int y = Integer.parseInt(String.valueOf(s.charAt(i+1)));
int z = Integer.parseInt(String.valueOf(s.charAt(i+2)));
int a = Integer.parseInt(String.valueOf(s.charAt(i+3)));
if(a==0){
res.append(String.valueOf(alphabet.charAt(x)));
}
else if(z==0){
res.append(String.valueOf(alphabet.charAt(x*10+y)));
i+=2;
}
else{
res.append(String.valueOf(alphabet.charAt(x)));
}
}
else{
int y = Integer.parseInt(String.valueOf(s.charAt(i+1)));
int z = Integer.parseInt(String.valueOf(s.charAt(i+2)));
if(z==0){
res.append(String.valueOf(alphabet.charAt(x*10+y)));
i+=2;
}
else{
res.append(String.valueOf(alphabet.charAt(x)));
}
}
}
}
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 | 90d5d0acf1a0804abebd40bdf7681482 | 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 EA {
static char[] letters = {'\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'};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
String str = sc.next();
System.out.println(solve(n,str));
}
}
public static String solve(int n,String str) {
if(str.length() == 0 || str.charAt(0) == '0') {
return null;
}
String res = "";
for(int i=str.length()-1;i>=0;i--) {
int num = str.charAt(i) - '0';
if(num == 0 && i < 2) {
return null;
}
else if(num == 0 && i>=2) {
int a = str.charAt(i-1)-'0';
int b = str.charAt(i-2) - '0';
int val = b*10+a;
res += letters[val] ;
i -= 2;
}
else {
res += letters[num] ;
}
}
String ans = "";
for(int i=0;i<res.length();i++) {
ans += res.charAt(res.length()-1-i);
}
return 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 | 9303d0206195bb4212533bcec6db9138 | 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 EA {
static char[] letters = {'\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'};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
String str = sc.next();
System.out.println(solve(n,str));
}
}
public static String solve(int n,String str) {
if(str.length() == 0 || str.charAt(0) == '0') {
return null;
}
String res = "";
for(int i=str.length()-1;i>=0;i--) {
int num = str.charAt(i) - '0';
if(num == 0 && i < 2) {
return null;
}
else if(num == 0 && i>=2) {
int a = str.charAt(i-1)-'0';
int b = str.charAt(i-2) - '0';
int val = b*10+a;
res += letters[val] ;
i -= 2;
}
else {
res += letters[num] ;
}
}
String ans = "";
for(int i=0;i<res.length();i++) {
ans += res.charAt(res.length()-1-i);
}
return 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 | 8abd828e460f582705b69f1452f717b9 | 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 Solve {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String str = sc.next();
StringBuilder sb = new StringBuilder();
int i = n-1;
while(i>=0){
char ch = str.charAt(i);
if(ch == '0'){
String sh = str.substring(i-2,i);
int ans = Integer.valueOf(sh);
sb.append((char)(ans + 96));
i = i-3;
}else{
sb.append((char)(ch-'0' + 96));
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 | abf5cf7856d3cc912975fd226ef6050d | 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 Codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int len = in.nextInt();
String s = in.next();
StringBuilder sb = new StringBuilder();
for (int j = len-1; j >= 0; j--) {
if (s.charAt(j) == '0') {
sb.append((char) (Integer.parseInt(s.substring(j-2,j)) + 96));
j-=2;
} else {
sb.append((char)(Integer.parseInt(s.substring(j, j+1)) + 96));
}
}
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 | d41e8be62e990fe44d698599d477c035 | 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 codeforces{
public static void main(String[] args) throws IOException {
Scanner s=new Scanner(System.in);
int tc=s.nextInt();
for (int j = 0; j < tc; j++) {
int n=s.nextInt();
s.nextLine();
String str=s.nextLine();
int index=n-1;
StringBuilder ans=new StringBuilder();
while(index>=0){
int k=index-2;
if(k<0) k=0;
if(str.charAt(index)!='0'){
// System.out.println((char)('a'+str.charAt(index)-'1'));
ans.append((char)('a'+(int)(str.charAt(index)-'1')));
index--;
}
else{
// System.out.println((char)('a'+Integer.parseInt(str.substring(k,index))));
ans.append((char)('a'+Integer.parseInt(str.substring(k,index))-1));
index=index-3;
}
}
System.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 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 | 17790956660735db5a3848ea9cbd7d64 | 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{
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
int T = s.nextInt();
while(T > 0){
int n = s.nextInt(); // length n
String m = s.next(); // encoded integer
System.out.println(solve(n, m));
T--;
}
}
static String solve(int n, String m){
String Str = String.valueOf(m);
String Res = "";
int i = n-1;
while(i>=0){
// System.out.println("check1");
char c = Str.charAt(i);
int in = Character.getNumericValue(c);
if(in != 0){
// System.out.println("check2");
String temp = "";
temp += String.valueOf((char)(in + 96));
temp += Res;
Res = temp;
i--;
// System.out.println(Res);
} else{
// System.out.println("check3");
int j = i;
String temp = "";
for(int k=j-2; k<j; k++){
temp += Str.charAt(k);
}
int tempInt = Integer.valueOf(temp);
String temp2 = "";
temp2 += String.valueOf((char)(tempInt + 96));
temp2 += Res;
Res = temp2;
i-=3;
// System.out.println(Res);
}
} return 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.