이것저것
C언어 swea 1940 가랏!RC카! 본문
https://swexpertacademy.com/main/identity/anonymous/loginPage.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
#include <stdio.h>
int RC_distance(){
int n, c, a,v=0,d=0;
scanf("%d", &n);
int i;
for(i = 0; i< n; i++){
scanf("%d ", &c); //0,1,2중 command값 받기
if(c != 0){
scanf("%d", &a);
// c가0이 아닌 경우에는 가속도 값 받기
}
switch(c){
case 0:
d += v;
//case0은 현재 속도 유지
break;
case 1:
//case1은 a만큼 가속도 증가
v += a;
d += v;
break;
case 2:
/*case3은 현재 속도보다 감속할 속도가 크면
속도는 0*/
v = a>v ? 0 : v-a;
d += v;
break;
}
}
return d;
}
int main(void){
int test_case, i;
scanf("%d", &test_case);
for(i = 0; i < test_case; i++){
int distance = RC_distance(); //함수 호출
printf("#%d %d\n", i+1, distance);
}
return 0;
}
'Language > C언어' 카테고리의 다른 글
| C언어 swea 1285 아름이의 돌던지기 (0) | 2020.11.19 |
|---|---|
| C언어 swea 1961 숫자 배열 회전 (0) | 2020.11.19 |
| C언어 swea 2001 파리퇴치 (0) | 2020.11.19 |
| C언어 swea 1966 숫자를 정렬하자 (0) | 2020.11.19 |
| C언어 swea 1976 시각 덧셈 (0) | 2020.11.19 |