Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Problem1
- {
- public static void main(String args[]) throws IOException
- {
- Scanner sc = new Scanner(System.in);
- int t = sc.nextInt();
- for (int i = 0; i<t ; i++)
- {
- int n = sc.nextInt();
- int k = sc.nextInt();
- StringBuilder sb=new StringBuilder("");
- for (int x = 0; x<n-2; x++)
- sb.append("a");
- sb.append("bb");
- System.out.println(sb);
- int length = sb.length();
- int b1 = length -2;
- int b2 = length -1;
- int iter = 1;
- while (b1 >0 || b2 >1 )
- {
- if (iter == k)
- {
- System.out.println(sb);
- break;
- }
- if (b1-b2 >1)
- {
- sb.replace(b2,b2+1,"a");
- sb.replace(b2-1,b2, "b");
- b2--;
- }
- else
- {
- sb.replace(b1,b1+1,"a");
- sb.replace(b1-1,b1, "b");
- b1--;
- }
- iter ++;
- }
- }
- }
- }
- class Scanner
- {
- StringTokenizer st;
- BufferedReader br;
- public Scanner(InputStream s)
- {
- br = new BufferedReader(new InputStreamReader(s));
- }
- public String next() throws IOException
- {
- while (st == null || !st.hasMoreTokens())
- st = new StringTokenizer(br.readLine());
- return st.nextToken();
- }
- public int nextInt() throws IOException
- {
- return Integer.parseInt(next());
- }
- public long nextLong() throws IOException
- {
- return Long.parseLong(next());
- }
- public String nextLine() throws IOException
- {
- return br.readLine();
- }
- public double nextDouble() throws IOException
- {
- String x = next();
- StringBuilder sb = new StringBuilder("0");
- double res = 0, f = 1;
- boolean dec = false, neg = false;
- int start = 0;
- if (x.charAt(0) == '-')
- {
- neg = true;
- start++;
- }
- for (int i = start; i < x.length(); i++)
- if (x.charAt(i) == '.')
- {
- res = Long.parseLong(sb.toString());
- sb = new StringBuilder("0");
- dec = true;
- } else
- {
- sb.append(x.charAt(i));
- if (dec)
- f *= 10;
- }
- res += Long.parseLong(sb.toString()) / f;
- return res * (neg ? -1 : 1);
- }
- public boolean ready() throws IOException
- {
- return br.ready();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement