-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package S4; | ||
|
||
import java.io.*; | ||
|
||
public class Boj_28086_미소녀컴퓨터파루빗토쨩 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
||
StringBuilder num1 = new StringBuilder(); | ||
StringBuilder num2 = new StringBuilder(); | ||
|
||
char[] chars = br.readLine().toCharArray(); | ||
num1.append(chars[0]); | ||
|
||
char order = '0'; | ||
int idx = 1; | ||
|
||
while (idx < chars.length) { | ||
if (chars[idx] == '+' | ||
|| chars[idx] == '-' | ||
|| chars[idx] == '*' | ||
|| chars[idx] == '/') { | ||
order = chars[idx++]; | ||
break; | ||
} | ||
num1.append(chars[idx++]); | ||
} | ||
|
||
while (idx < chars.length) { | ||
num2.append(chars[idx++]); | ||
} | ||
|
||
long n1 = Long.parseLong(num1.toString(), 8); | ||
long n2 = Long.parseLong(num2.toString(), 8); | ||
|
||
if (order == '+') { | ||
bw.write(Long.toString(n1 + n2, 8)); | ||
} else if (order == '-') { | ||
bw.write(Long.toString(n1 - n2, 8)); | ||
} else if (order == '*') { | ||
bw.write(Long.toString(n1 * n2, 8)); | ||
} else { | ||
bw.write(n2 == 0 ? "invalid" | ||
: Long.toString((long) Math.floor((double) n1 / (double) n2), 8)); | ||
} | ||
|
||
bw.flush(); | ||
} | ||
} |