CS/Algorithm 문제

[SW Expert Academy] 2071. 평균값 구하기

심심231 2019. 9. 15. 01:46

 

문제

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QRnJqA5cDFAUq

 

 

 

코드

 

 

#include <iostream>
#include <math.h>

using namespace std;

int main(void) 
{
	int result = 0; //result of calculation
	int n = 0; //number of test cases
	cin >> n;
	float* test = new float[n]; //store result

	for (int i = 0; i < n; i++) {
		result = 0;
		for (int j = 0; j < 10; j++) {
			int tmp = 0;
			cin >> tmp;
			result += tmp;
		}
		test[i] = floor((result + 5) / 10);
	}

	for (int i = 0; i < n; i++) { //print result
		cout << "#" << i + 1 << " " << test[i] << endl;
	}
    
    return 0;
}

 

 

 

 

 

찾아본것

- new/delete

  [C++] new/delete 이용한 2차원 배열 동적할당

 

- 소수점 반올림/올림/내림/버림

  [C++] 소수점 반올림/올림/내림/버림

 

 

 

 

728x90
반응형