PS/BOJ

백준 10984 (C++) 내 학점을 구해줘

akinakamori 2021. 9. 26. 23:18
728x90
SMALL
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
const int MAX = 101;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, c, tot_c = 0;
        double g, tot_g = 0.0, GPA = 0.0;
        cin >> n;
        while (n--) {
            cin >> c >> g;
            tot_c += c;
            tot_g += g * c;
        }
        cout << fixed;
        cout.precision(1);
        cout << tot_c << " " << tot_g / tot_c << '\n';
    }
    return 0;
}

부동소수점 c++로도 해보기~

반복문 인덱스 참조할 일 없으면 웬만해선 while문을 쓰려는 편

 

728x90
LIST

'PS > BOJ' 카테고리의 다른 글

백준 2581 (C++) 소수  (0) 2021.09.28
백준 1717 (C++) 집합의 표현  (0) 2021.09.28
백준 4386 (C++) 별자리 만들기  (0) 2021.09.26
백준 7346 (C++) 유전자 함수  (0) 2021.09.26
백준 4963번 (C++) 섬의 개수  (0) 2021.09.26