zj3t

email: euntaejang@gmail.com

Latest Posts

Algospot-CONVERT

By 오후 1:17

코드만 보고도 이해가 가실거에요~~쉬운문제였습니다.


#include <stdio.h>

int main() {
int test;
double input = 0;
char arrays[100] = { 0,};

double kg = 2.2046;
double  lb = 0.4536;
double l = 0.2642;
double g = 3.7854;

scanf_s("%d", &test);
for (int i = 0; i < test; i++) {
scanf_s("%lf %s", &input, arrays, sizeof(arrays));

if (arrays[0] == 'k') { //kg라면
printf("%d %.4f lb\n", i + 1, input*kg);
goto exit_;
}
else if (arrays[0] == 'g') {//gallon이라면
printf("%d %.4f l\n", i + 1, input*g);
}
else if (arrays[1] == 'b' && arrays[0] == 'l') {//lb라면
printf("%d %.4f kg\n", i + 1, input*lb);
}
else if (arrays[0] == 'l') { //liter라면
printf("%d %.4f g\n", i + 1, input*l);
}
exit_:
arrays[0] = 0;
arrays[1] = 0;
}
return 0;
}


You Might Also Like

0 개의 댓글