"SWEA 2043 서랍의 비밀번호"의 두 판 사이의 차이

 
(사용자 3명의 중간 판 8개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;SWEA-2043 서랍의 비밀번호
{{SWEA|난이도=1}}
* K부터 몇번 증가하면 P가 되는가?  
* K부터 몇번 증가하면 P가 되는가?  
:X = P - K + 1
:= P - K + 1
* P보다 K가 작을 경우에는, 위의 식으로 대응이 되지 않겠으나...
* P보다 K가 작을 경우에는, 위의 식으로 대응이 되지 않겠으나...
* 테스트케이스에는 'P > K'인 경우만 있어서 위의 식만으로 통과된다.
* 테스트케이스에는 'P > K'인 경우만 있어서 위의 식만으로 통과된다.
{{SWEA 헤더}}
{{SWEA 난이도 1-2}}
|}


==C++==
==C++==
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
#include <iostream>
#include <iostream>
using namespace std;
using namespace std;
19번째 줄: 15번째 줄:
     cout << P - K + 1;
     cout << P - K + 1;
}
}
</source>
</syntaxhighlight>


==Java==
==Java==
<source lang='java'>
<syntaxhighlight lang='java'>
import java.util.Scanner;
import java.util.Scanner;
class Solution {
class Solution {
32번째 줄: 28번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>
 
==Python==
<syntaxhighlight lang='python'>
#kcy_code1
a, b = map(int, input().split())
cnt = 1
while(1):
    if a == b:
        print(cnt)
        break
    b = b + 1
    cnt = cnt + 1
</syntaxhighlight>
<syntaxhighlight lang='python'>
#kcy_code2
p, k = map(int, input().split())
print(p - k +1)
</syntaxhighlight>


==같이 보기==
==같이 보기==

2023년 8월 25일 (금) 01:41 기준 최신판

1 개요[ | ]

SWEA 2043 서랍의 비밀번호
해 = P - K + 1
  • P보다 K가 작을 경우에는, 위의 식으로 대응이 되지 않겠으나...
  • 테스트케이스에는 'P > K'인 경우만 있어서 위의 식만으로 통과된다.

2 C++[ | ]

#include <iostream>
using namespace std;
int main() {
    int P, K;
    cin >> P >> K;
    cout << P - K + 1;
}

3 Java[ | ]

import java.util.Scanner;
class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();
        int K = sc.nextInt();
        System.out.print(P-K+1);
    }
}

4 Python[ | ]

#kcy_code1
a, b = map(int, input().split())
cnt = 1
while(1):
    if a == b:
        print(cnt)
        break
    b = b + 1
    cnt = cnt + 1
#kcy_code2
p, k = map(int, input().split())
print(p - k +1)

5 같이 보기[ | ]

6 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}