Advertisement
Guest User

ProblemB

a guest
Mar 26th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Problem1
  5. {
  6.  
  7. public static void main(String args[]) throws IOException
  8. {
  9. Scanner sc = new Scanner(System.in);
  10. int t = sc.nextInt();
  11. for (int i = 0; i<t ; i++)
  12. {
  13. int n = sc.nextInt();
  14. int k = sc.nextInt();
  15. StringBuilder sb=new StringBuilder("");
  16. for (int x = 0; x<n-2; x++)
  17. sb.append("a");
  18. sb.append("bb");
  19. System.out.println(sb);
  20. int length = sb.length();
  21. int b1 = length -2;
  22. int b2 = length -1;
  23. int iter = 1;
  24. while (b1 >0 || b2 >1 )
  25. {
  26. if (iter == k)
  27. {
  28. System.out.println(sb);
  29. break;
  30. }
  31. if (b1-b2 >1)
  32. {
  33. sb.replace(b2,b2+1,"a");
  34. sb.replace(b2-1,b2, "b");
  35. b2--;
  36. }
  37. else
  38. {
  39. sb.replace(b1,b1+1,"a");
  40. sb.replace(b1-1,b1, "b");
  41. b1--;
  42. }
  43. iter ++;
  44. }
  45. }
  46. }
  47. }
  48.  
  49.  
  50. class Scanner
  51. {
  52. StringTokenizer st;
  53. BufferedReader br;
  54.  
  55. public Scanner(InputStream s)
  56. {
  57. br = new BufferedReader(new InputStreamReader(s));
  58. }
  59.  
  60. public String next() throws IOException
  61. {
  62. while (st == null || !st.hasMoreTokens())
  63. st = new StringTokenizer(br.readLine());
  64. return st.nextToken();
  65. }
  66.  
  67. public int nextInt() throws IOException
  68. {
  69. return Integer.parseInt(next());
  70. }
  71.  
  72. public long nextLong() throws IOException
  73. {
  74. return Long.parseLong(next());
  75. }
  76.  
  77. public String nextLine() throws IOException
  78. {
  79. return br.readLine();
  80. }
  81.  
  82. public double nextDouble() throws IOException
  83. {
  84. String x = next();
  85. StringBuilder sb = new StringBuilder("0");
  86. double res = 0, f = 1;
  87. boolean dec = false, neg = false;
  88. int start = 0;
  89. if (x.charAt(0) == '-')
  90. {
  91. neg = true;
  92. start++;
  93. }
  94. for (int i = start; i < x.length(); i++)
  95. if (x.charAt(i) == '.')
  96. {
  97. res = Long.parseLong(sb.toString());
  98. sb = new StringBuilder("0");
  99. dec = true;
  100. } else
  101. {
  102. sb.append(x.charAt(i));
  103. if (dec)
  104. f *= 10;
  105. }
  106. res += Long.parseLong(sb.toString()) / f;
  107. return res * (neg ? -1 : 1);
  108. }
  109.  
  110. public boolean ready() throws IOException
  111. {
  112. return br.ready();
  113. }
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement