Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with places after the decimal.
음수, 0, 양수의 비율을 구하는 문제로 비율은 나눗셈 연산이라 쉽지만
소숫점 아래 자리를 고정하는 걸 remind하는 문제다.
cout<<fixed;
cout.precision(6);
를 사용했다.
void plusMinus(vector<int> arr) {
float minus=0, zero=0,plus=0;
int total=arr.size();
sort(arr.begin(),arr.end());
for(int elem : arr){
if(elem<0)minus++;
else if(elem == 0) zero++;
else plus++;
}
cout<<fixed;
cout.precision(6);
cout<<plus/total<<"\n"<<minus/total<<"\n"<<zero/total;
}