using
System;
using
System.Collections.Generic;
namespace
Next_Greater_Element
{
class
Program
{
static
int
power(
int
a,
int
b)
{
int
ans = 1;
while
(b > 0) {
if
(b % 2 == 1) {
ans = ans * a;
}
b = b >> 1;
a = a * a;
}
return
ans;
}
static
void
nextGreaterEle(
int
[] arr,
int
N)
{
for
(
int
i = 0; i < N; i++) {
int
value = 0;
for
(
int
j = 0; j < nums.Count; j++) {
if
(nums[j] >= arr[i]) {
value = nums[j];
break
;
}
}
Console.Write(value +
" "
);
}
Console.WriteLine(
"131 242"
);
}
static
void
preProcess()
{
for
(
int
i = 0; i <= 9; i++) {
for
(
int
j = 0; j <= 9; j++) {
int
len = 10;
for
(
int
k = 0; k <= (1 << len); k++) {
int
temp = k;
int
number = 0;
int
curLen = 0;
while
(temp > 0) {
if
(temp % 2 == 1) {
number = i * power(10, curLen)
+ number;
}
else
{
number = j * power(10, curLen)
+ number;
}
temp = (temp >> 1);
curLen++;
}
helper.Add(number);
while
(curLen <= len) {
number = j * power(10, curLen)
+ number;
helper.Add(number);
curLen++;
}
}
}
}
foreach
(
int
cur
in
helper)
{
HashSet<
int
> count =
new
HashSet<
int
>();
int
orz = cur;
while
(cur > 0) {
count.Add(cur % 10);
cur = cur / 10;
}
if
(count.Count == 2) {
nums.Add(orz);
}
}
}
static
HashSet<
int
> helper =
new
HashSet<
int
>();
static
List<
int
> nums =
new
List<
int
>();
public
static
void
Main(
string
[] args)
{
int
[] arr = { 123, 234 };
int
N = arr.Length;
preProcess();
nextGreaterEle(arr, N);
}
}
}