C++)
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, temp;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> temp;
v.push_back(temp);
}
int ans = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (v[j] <= v[i])
ans += 1;
}
}
cout << ans << "\n";
}
return 0;
}
Python)
import sys
read = sys.stdin.readline
t = int(read().rstrip())
for _ in range(t):
n = int(read().rstrip())
a = list(map(int, read().rstrip().split()))
ans = 0
for idx, ele in enumerate(a[1:], start = 1):
for j in a[:idx]:
ans += (1 if j <= ele else 0)
print(ans)
'백준 1 > 기초' 카테고리의 다른 글
| [백준 2941] 크로아티아 알파벳 (C++/Python) (0) | 2020.12.05 |
|---|---|
| [백준 16861] Harshad Numbers (C++/Python) (0) | 2020.12.05 |
| [백준 2775] 부녀회장이 될테야 (C++/Python) (0) | 2020.12.05 |
| [백준 2908] 상수 (C++/Python) (0) | 2020.12.05 |
| [백준 1316] 그룹 단어 체커 (C++/Python) (0) | 2020.12.05 |