-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVeci.java
More file actions
59 lines (53 loc) · 1.82 KB
/
Copy pathVeci.java
File metadata and controls
59 lines (53 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.Arrays;
import java.util.Scanner;
import java.io.*;
import java.util.*;
public class Veci {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
int answer = -1;
boolean hasAnswer = false;
for(int i = input+1; i <= 999999 && hasAnswer == false;i++)
{
if(Integer.toString(i).length() == Integer.toString(input).length())
{
String inputString = Integer.toString(input);
String iValue = Integer.toString(i);
boolean isSolution = true;
for(int j = 0; j < inputString.length(); j++)
{
int charCount1 = 0;
int charCount2 = 0;
for(int k = 0; k < inputString.length();k++)
{
if(inputString.charAt(j) == inputString.charAt(k))
{
charCount1++;
}
}
for(int k = 0; k < inputString.length();k++)
{
if(inputString.charAt(j) == iValue.charAt(k))
{
charCount2++;
}
}
if(charCount1 != charCount2)
{
isSolution = false;
}
}
if(isSolution)
{
System.out.print(i);
hasAnswer = true;
}
}
}
if(hasAnswer == false)
{
System.out.print("0");
}
}
}