PS

SWEA [D3] - 18662. 등차수열 만들기 (C언어)

kugnuoy 2023. 11. 8. 14:45

[18662]

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&problemLevel=3&problemLevel=4&contestProbId=AYo-e9EKmGoDFAQI&categoryId=AYo-e9EKmGoDFAQI&categoryType=CODE&problemTitle=%EB%93%B1%EC%B0%A8&orderBy=RECOMMEND_COUNT&selectCodeLang=ALL&select-1=4&pageSize=10&pageIndex=1&problemLevel=2%2C3%2C4&&&&&&&&&

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

[코드]

#include <stdio.h>

float find_min(float x, float y, float z) {
	if (x < 0)	x = -x;
	if (y < 0)	y = -y;
	if (z < 0)	z = -z;

	if (x <= y && x <= z)	return x;
	else if (y <= x && y <= z)	return y;
	else return z;
}

int main() {
	
	int T;
	scanf("%d", &T);

	for (int t = 0; t < T; t++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);

		float min;
		min = find_min((float)2 * b - a - c, (float)0.5*c - b + 0.5*a, (float)2 * b - a - c);

		printf("#%d %.1f\n", t + 1, min);
	}

}