https://www.acmicpc.net/problem/10818 : 최소, 최대
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
int n = 0;
cin >> n;
int *num = new int[n];
for (int i = 0; i < n; i++){
int a;
cin >> a;
num[i] = a;
}
sort(num, num + n);
cout << num[0] << " " << num[n-1] << endl;
delete[] num;
}
-> algorithm 헤더파일에 sort 함수 사용
https://www.acmicpc.net/problem/2562 : 최댓값
#include <iostream>
using namespace std;
int main(void){
int max = -1, num = 0;
for(int i=0; i<9; i++){
int a;
cin >> a;
if(max < a){
max = a;
num = i+1;
}
}
cout << max << endl;
cout << num << endl;
}
리스트 안쓰고.. 그냥.....
https://www.acmicpc.net/problem/2577 : 숫자의 개수
#include <iostream>
using namespace std;
int main(void){
int a, b, c;
int arr[10] = {0};
cin >> a >> b >> c;
int num = a * b * c;
while(num != 0){
arr[num%10]++;
num /= 10;
}
for(int i=0; i<10; i++){
cout << arr[i] << endl;
}
}
https://www.acmicpc.net/problem/3052 : 나머지
#include <iostream>
using namespace std;
int main(void){
int arr[42] = {0};
for(int i=0; i<10; i++){
int num;
cin >> num;
arr[num%42]++;
}
int count = 0;
for(int i=0; i<42; i++){
if(arr[i]!=0) count++;
}
cout << count;
}
https://www.acmicpc.net/problem/1546 : 평균
#include <iostream>
using namespace std;
int main(void){
int n, max = 0;
double total = 0;
cin >> n;
double *score = new double[n];
double *n_score = new double[n];
for(int i = 0; i < n; i++){
double s;
cin >> s;
score[i] = s;
max = (s > max) ? s : max;
}
for(int i = 0; i < n; i++){
n_score[i] = score[i] * 100 / max ;
total += n_score[i];
}
cout << total/n << endl;
}
https://www.acmicpc.net/problem/8958 : OX 퀴즈
#include <iostream>
using namespace std;
int main(void){
int n;
cin >> n;
for(int i=0; i<n; i++){
int total = 0, score = 0;
string test;
cin >> test;
for (int i = 0; i < test.length(); i++){
if(test[i] == 'O'){
score += 1;
total += score;
}else{
score = 0;
}
}
cout << total << endl;
total = 0, score = 0;
}
}
https://www.acmicpc.net/problem/4344 : 평균은 넘겠지
#include <iostream>
using namespace std;
int main(void){
int c;
cin >> c;
for(int i = 0; i < c; i++){
int n;
double total = 0;
cin >> n;
int *score = new int[n];
for(int j=0; j<n; j++){
cin >> score[j];
total += score[j];
}
double avg = total / n;
double m = 0;
for(int j=0; j<n; j++){
if(score[j] > avg)
m += 1;
}
double per = m * 100 / n;
printf("%.3f%%\n", per);
}
}
하면 할수록 파이썬이 최고라는 생각만 드는걸.....?...... 파이썬 최고다...