A - Train Car 解説 by en_translator
If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
Original proposer: vwxyz
For each car, assign numbers \(1,2,\dots,N\) from the front to back.
The \(K\)-th car from the front has the car number \(K\).
Behind this car are the \((N-K)\) cars numbered \(K+1,K+2,\dots,N\).
Hence, car \(K\) is the \((N-K+1)\)-th car from the back.
Sample code in C++
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,K;
cin>>N>>K;
cout<<N-K+1<<"\n";
}
Sample code in Python
N,K=map(int,input().split())
print(N-K+1)
投稿日時:
最終更新: