47. 콘솔에서 두 정수(a,b)를 입력 받아 a와b가 같으면 1, 같지않으면 0 을 출력하라.
입력 : 1Line 으로 a,b가 공백을 두고 입력된다.
입력 범위 : -2147483648 ~ 2147483647
입력 예시
9 1
출력 예시
0
JAVA
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int flagValue = scan.nextInt();
if(flagValue== scan.nextInt()) {
System.out.println(1);
} else {
System.out.println(0);
}
scan.close();
}
}
Swift 4.2
import Foundation
let line = readLine()
if line != nil {
let split = line!.split(separator: " ")
if split.count == 2, let a = Int(split[0]), let b = Int(split[1]) {
print(String.init(format: "%d", (a==b)))
}
}
48. 콘솔에서 두 정수(a,b)를 입력 받아 b가 a보다 크거나 같으면1, b가 a보다 작으면 0을 추렭하라
입력 : 1Line 으로 a,b가 공백을 두고 입력된다.
입력 범위 : -2147483648 ~ 2147483647
입력 예시
0 -1
출력 예시
0
JAVA
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int flagValue = scan.nextInt();
if(flagValue <= scan.nextInt()) {
System.out.println(1);
} else {
System.out.println(0);
}
scan.close();
}
}
Swift 4.2
import Foundation
let line = readLine()
if line != nil {
let split = line!.split(separator: " ")
if split.count == 2, let a = Int(split[0]), let b = Int(split[1]) {
print(String.init(format: "%d", (a<=b)))
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int flagValue = scan.nextInt();
if(flagValue != scan.nextInt()) {
System.out.println(1);
} else {
System.out.println(0);
}
scan.close();
}
}
Swift 4.2
import Foundation
let line = readLine()
if line != nil {
let split = line!.split(separator: " ")
if split.count == 2, let a = Int(split[0]), let b = Int(split[1]) {
print(String.init(format: "%d", (a != b)))
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long value = scan.nextInt();
scan.close();
System.out.println(value << 1);
}
}
Swift 4.2
import Foundation
let line = readLine()
if line != nil {
if let value = Int(line!) {
print(value << 1)
}
}
시프트 연산 오랜만에 하네요.
솔직히 잘 기억도 안납니다.
저는 국딩이 아닙니다. 제 나이때 주변 애들은 전부 정보교육?인가 해서 한참 교과목으로 컴퓨터를 배우던때가 있습니다.
아 그리운 플로피디스크여~
아무튼 그때 교산지 강산지, 선생님의 왈 " 컴퓨터는 덧셈밖에못하는 바보야! "
그리고 시간이 흘러
저의 왈 " 선생님! 바보! "
컴퓨터는 곱셈연산, 그러니까 2진수의 시프트 연산으로 사람이 하는 곱셈과 유사한일을 할 수 있습니다.
주의점은 나열된 1과 0을 그대로 오른쪽 왼쪽으로 움직이는거라 예상치 못한 동작을 하기도합니다.
뭐 이런건 따로 검색해보세요
꽤나 덧셈 뺄셈 곱셈 나눗셈 연산을 재미지게 합니다.
기본적으로 C를 기반으로 작성된 문제이기때문에 이대로 가다보면 매크로연산정의하는 문제도 나오지않을까합니다.
입력 : 정수 두 개가 공백을 두고 1line으로 입력된다. ( 입력 범위: a >= 0, b <= 10 )
입력 예시
2 3
출력 예시
16
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int base = scan.nextInt();
int exp = scan.nextInt();
scan.close();
if(base >= 0 && exp <= 10 ) {
System.out.println(base << exp);
}
}
}
Swift
import Foundation
let line = readLine()
if line != nil {
let split = line!.split(separator: " ")
if split.count == 2, let base = Int(split[0]), let exp = Int(split[1]) {
if base >= 0 , exp <= 10 {
print(base << exp)
}
}
}
46. 콘솔에서 두 정수(a,b)를 입력 받아 a가 b보다 크면 1, 그외 라면 0 을 출력하라.
입력 : 1Line 으로 a,b가 공백을 두고 입력된다.
입력 범위 : -2147483648 ~ 2147483647
입력 예시
9 1
출력 예시
1
JAVA
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int flagValue = scan.nextInt();
scan.close();
if(flagValue > scan.nextInt()) {
System.out.println(1);
} else {
System.out.println(0);
}
}
}
Swift 4.2
import Foundation
let line = readLine()
if line != nil {
let split = line!.split(separator: " ")
if split.count == 2, let a = Int(split[0]), let b = Int(split[1]) {
print(String.init(format: "%d", (a>b)))
}
}
bool형 변수는 사실 0 과 1 이다! 라는걸 보여주려는 문제인거같은데
JAVA에서 bool을 바로 정수형으로 보여주기가 어찌해야할지 모르겠어서 결국그냥 1,0을 써서 출력했네요.