2월 14일 손해본 금액

64 views
Skip to first unread message

cybe...@gmail.com

unread,
Feb 13, 2013, 8:50:38 PM2/13/13
to kor...@googlegroups.com
프로그램 명: business
제한시간: 1 초

4 개의 정수가 입력으로 주어진다.

40 70 50 20
차례대로
  • 원가 -- 40
  • 정가(판매가) -- 70
  • 손님이 물건값으로 지불한 돈 중 가짜 돈 -- 50
  • 주인이 손님에게 거스름돈으로 지불한 돈 -- 20
문제의 내용은
  • 정가가 70 원 인데 , 주인이 손님에게 거슬러 준 돈이 20 원 이므로 손님이 주인에게 지불한 금액은 90 원으로 유추 할 수 있다.
  • 이 중 50 원이 가짜 돈이므로 진짜 돈은 40 원 이다.
  • 즉 주인이 받는 진짜 금액이 40 원에서 주인이 거슬러 준 돈이 20 원 이므로 실제적으로 주인이 받은 금액은 20 원.
  • 그런데 원가가 40 원이므로 주인은 20 원의 손해를 본 것이다.

입력

4 개의 정수 값 N , M , P , C 가 입력으로 주어진다. 각각은 0 에서 500000 사이다.
  • 원가
  • 정가
  • 위조 지폐 금액
  • 거스름돈

N < M 이고 P <= M + C . 즉 C 를 보면 손님이 지불한 금액을 알수 있고 그 중 P 원이 위조 지폐이다. 물론 지불한 돈 모두가 위조 지폐일 수가 있다.

예를 들어

40 70 100 30
원가가 40 원이고 정가가 70 원인 물건을 거스름돈 30 원을 주었으니 손님이 지불한 금액은 100 원이고 이 돈 모두 위조 금액이다.

출력

주인이 (손해를 본 경우에는 양수 , 손해도 이익도 아니면 0 , 이익을 본 경우는 음수) 금액을 출력한다.
  • 70원을 손해 보았을 경우 -> 출력값 : 70
  • 손해도 이익도 아닐 경우 -> 출력값 : 0
  • 60원을 이익 보았을 경우 -> 출력값 : -60

입출력 예

입력

40 70 100 30
 
출력

70

입력

40 70 50 20

출력

20

입력

14604 32391 3902 153

출력

-13885
출처:POJ Monthly--2005.07.31, Wang Yijie

cybe...@gmail.com

unread,
Feb 13, 2013, 9:40:26 PM2/13/13
to kor...@googlegroups.com
public static void main(String[] args){
int cost; //원가
int sale; //정가
int sham; //가짜돈
int pay; //지불
int wrong; //손해금액
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("입력");
cost = sc.nextInt();
sale = sc.nextInt();
sham = sc.nextInt();
pay = sc.nextInt();
if(!(cost < sale))System.out.println("원가가 정가보다 많습니다.");
else if(!(sham <= sale + pay))System.out.println("가짜돈이 지불한 돈보다 많습니다.");
else {
sc.close();
break;
}
}
wrong = ((sale + pay) - sham) - cost - pay;
System.out.println(-(wrong));
}

선해

unread,
Feb 13, 2013, 9:46:00 PM2/13/13
to KorUsn
import java.util.Scanner;

public class Test3 {
public static void main(String[] args){
int N,M,P,C,money;

Scanner sc = new Scanner(System.in);
N = sc.nextInt(); //원가
M = sc.nextInt(); //정가
P = sc.nextInt(); //손님의 위조지폐
C = sc.nextInt(); //주인이 손님에게 거슬러 준 돈

money = -(M-P-N);

System.out.println(money);
}
}

권기륜

unread,
Feb 13, 2013, 9:47:29 PM2/13/13
to kor...@googlegroups.com
import java.util.Scanner;
public class Business {
public static void main(String[] args) {
int N,M,P,C;
Scanner sc=new Scanner(System.in);
N=sc.nextInt();
M=sc.nextInt();
P=sc.nextInt();
C=sc.nextInt();
System.out.print(N-(((M+C)-P)-C));
}
}
Message has been deleted

김민찬

unread,
Feb 13, 2013, 10:09:44 PM2/13/13
to kor...@googlegroups.com
business

import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int prime_cost = sc.nextInt();
int price = sc.nextInt();
int fake = sc.nextInt();
int change = sc.nextInt();
System.out.println(fake + prime_cost - price);
}
}


경과시간별 순위:
전체: 2783/2868
Java :87/176
코드size 순위:
전체:2622/2868
Java:68/176

Message has been deleted
Message has been deleted
Message has been deleted

성관

unread,
Feb 13, 2013, 10:36:08 PM2/13/13
to kor...@googlegroups.com
import java.util.Scanner;

public class business {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N, M, P, C;
System.out.print("입력 : ");
N = sc.nextInt();
M = sc.nextInt();
P = sc.nextInt();
C = sc.nextInt();
if(N<M & P<=M+C & M>M+C-P)
System.out.println(M-(M+C-P));
else if(N<M & P<=M+C & M<M+C-P)
System.out.println(M-(M+C-P));
else if(N<M & P<=M+C & M==M+C-P)
System.out.println(M-(M+C-P));
}
}


Message has been deleted

qgqg...@gmail.com

unread,
Feb 13, 2013, 10:41:33 PM2/13/13
to kor...@googlegroups.com
import java.util.Scanner;

public class business {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a,b,c,d;
        int e,f,g;
       
        a = sc.nextInt();//원가
        b = sc.nextInt();//정가
        c = sc.nextInt();//가짜돈
        d = sc.nextInt();//거스름돈
        
        e = b+d;//받은 금액 = 원가+거스름돈
        f = e-c;//진짜돈 = 받은금액 - 가짜돈
        g = f-d;//받은 실제돈 = 진짜돈-거스름돈

        System.out.println(a-g);//손해본돈

    }
}

경과시간별 순위:

    전체: 2795/2872
    Java :100/180

코드size 순위:

    전체:2813/2872
    Java:152/180

Suyeon Kim

unread,
Feb 13, 2013, 10:42:29 PM2/13/13
to kor...@googlegroups.com
import java.util.Scanner;

public class Main {

public static void main(String[] args){
int N, M, P, C; //원가,정가,위조,거스름돈
int result;

Scanner sc=new Scanner(System.in);

N=sc.nextInt();
M=sc.nextInt();
P=sc.nextInt();
C=sc.nextInt();

result=N-(M-P);

System.out.println(result);


}

}
Message has been deleted
Message has been deleted
Message has been deleted

Gee-Eun KIM

unread,
Feb 13, 2013, 11:51:31 PM2/13/13
to kor...@googlegroups.com

import java.util.Scanner;


public class Test3 {

public static void main(String[] args) {
int n,m,p,c;
int result;
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
p=sc.nextInt();
c=sc.nextInt();
result= -(m-p-n);
System.out.println(result);
}

}

Message has been deleted
Message has been deleted
Message has been deleted

정영재

unread,
Feb 14, 2013, 12:03:34 AM2/14/13
to kor...@googlegroups.com
import java.util.Scanner;

public class business {

public static void main(String[] args) {
int N, M, P, C;
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
P = sc.nextInt();
C = sc.nextInt();
int D = M + C - P - C;
int R = N - D;
System.out.println(R);
}

}
Message has been deleted

SooYeon park

unread,
Feb 14, 2013, 12:05:54 AM2/14/13
to kor...@googlegroups.com
import java.util.Scanner;


public class Dovlet{
public static void main(String[] args) {
int N,M,P,C;
int money;
Scanner sc= new Scanner(System.in);
N=sc.nextInt();//원가
M=sc.nextInt();//정가
P=sc.nextInt();//위조지폐금액
C=sc.nextInt();//거스름돈
money=N-(M-P);
System.out.println(money);
}
}

이정욱

unread,
Feb 14, 2013, 12:06:27 AM2/14/13
to kor...@googlegroups.com
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        int N, M, P, C;
 
        Scanner sc = new Scanner(System.in);
 
        N = sc.nextInt();
 
        M = sc.nextInt();
 
        P = sc.nextInt();
 
        C = sc.nextInt();
         
        System.out.println(-(((M+C) - (P+C))-N));
    }
}

BAE, JUNGWON

unread,
Feb 14, 2013, 12:13:31 AM2/14/13
to kor...@googlegroups.com
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
int costPrice; //원가
int sellPrice; //정가
int fakeMoney; //가짜돈
int change;    //거스름돈 
int result;
Scanner sc = new Scanner(System.in);
costPrice = sc.nextInt();
sellPrice = sc.nextInt();
fakeMoney = sc.nextInt();
change = sc.nextInt();
result = sellPrice + change;   
result = result - change;   
result = costPrice - result;   
result = result + fakeMoney;   
System.out.println(result);
}
}
 

kimmo...@gmail.com

unread,
Feb 14, 2013, 3:03:32 AM2/14/13
to kor...@googlegroups.com
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
int N, M, P, C;
int result;

Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
P = sc.nextInt();
C = sc.nextInt();

result = (N + C) - ((M + C) - P);
System.out.println(result);

}

}
Reply all
Reply to author
Forward
0 new messages