doctscoder
하고싶은일있는개발
doctscoder
전체 방문자
오늘
어제
  • 분류 전체보기 (305)
    • 코테용 문제풀이 (304)
      • 백준 (272)
      • 알고스팟 (32)
    • 공부계획 (1)

최근 글

hELLO · Designed By 정상우.
doctscoder

하고싶은일있는개발

코테용 문제풀이/백준

사분면 고르기 풀이

2022. 12. 30. 23:26

문제 링크: https://www.acmicpc.net/problem/14681

백준 조건문 4단계 - 14681번 사분면 고르기를 풀어보았다.

 

풀이: 좌표를 받아 어느 사분면에 있는지 출력하면 된다.

 

C++

#include <iostream>

using namespace std;
int main() {
  int x,y;
  cin >> x;
	cin >> y;
	if(x>0&&y>0)
	{
		cout<<1;
	}
	if(x<0&&y>0)
	{
		cout<<2;
	}
	if(x<0&&y<0)
	{
		cout<<3;
	}
	if(x>0&&y<0)
	{
		cout<<4;
	}
}

Python

x=int(input())
y=int(input())
if(x>0 and y>0): print(1)
if(x<0 and y>0): print(2)
if(x<0 and y<0): print(3)
if(x>0 and y<0): print(4)

Java

import java.util.Scanner;

class Main 
{
  public static void main(String[] args)
  {
      Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      if(a>0&&b>0) System.out.println(1);
      if(a<0&&b>0) System.out.println(2);
      if(a<0&&b<0) System.out.println(3);
      if(a>0&&b<0) System.out.println(4);
  }
}

 

저작자표시 비영리 변경금지 (새창열림)

'코테용 문제풀이 > 백준' 카테고리의 다른 글

오븐 시계 풀이  (0) 2022.12.30
알람 시계 풀이  (0) 2022.12.30
윤년 풀이  (0) 2022.12.30
시험 성적 풀이  (0) 2022.12.30
두 수 비교하기 풀이  (0) 2022.12.30
    '코테용 문제풀이/백준' 카테고리의 다른 글
    • 오븐 시계 풀이
    • 알람 시계 풀이
    • 윤년 풀이
    • 시험 성적 풀이
    doctscoder
    doctscoder
    코딩 관련 공부를 적어놓는 블로그

    티스토리툴바