More actions
imported>qa22ahj No edit summary |
(Repair batch-0008 pages from live compare) |
||
| Line 14: | Line 14: | ||
int bitSum = 0; | int bitSum = 0; | ||
String str = Integer.toString(i); | String str = Integer.toString(i); | ||
String | String [] bits = str.split(""); | ||
for(String each : bits) { | for(String each : bits) { | ||
if (each.matches("")) { | if (each.matches("")) { | ||
| Line 28: | Line 28: | ||
} | } | ||
public static void main(String | public static void main(String[] args) { | ||
try { | try { | ||
BufferedReader br = new BufferedReader(new FileReader("test.txt")); | BufferedReader br = new BufferedReader(new FileReader("test.txt")); | ||
| Line 47: | Line 47: | ||
---- | ---- | ||
(zeropage)코드레이스출동 연습 | |||
---- | ---- | ||
[[프로그래밍]] | [[프로그래밍]] | ||
Latest revision as of 01:40, 27 March 2026
걸린 시간 : 20분
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class DigitGenerator {
private static int processOneCase(String line) {
int number = Integer.parseInt(line);
for(int i = 1; i < number; i++) {
int bitSum = 0;
String str = Integer.toString(i);
String [] bits = str.split("");
for(String each : bits) {
if (each.matches("")) {
continue;
}
bitSum += Integer.parseInt(each);
}
if (i + bitSum == number) {
return i;
}
}
return 0;
}
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("test.txt"));
String line = br.readLine();
int testCase = Integer.parseInt(line);
for(int i = 0; i < testCase; i++) {
line = br.readLine();
int result = processOneCase(line);
System.out.println(result);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
(zeropage)코드레이스출동 연습