본문 바로가기

Clipper 스터디

백준 2주차

2563

깃헙 링크: https://github.com/seulgib/Clipper_Baekjoon.git

 

GitHub - seulgib/Clipper_Baekjoon

Contribute to seulgib/Clipper_Baekjoon development by creating an account on GitHub.

github.com

<색종이 너비 구하기>

//색종이 너비구하기
//겹치는 너비 뺴야함.
#include <iostream>
#include <vector>
#include <cmath>
#define LENGTH 10
using namespace std;
int main(void) {
int n;
cin >> n;
vector <pair< int, int >> input(n);
 
int first, second;
for (int i = 0; i < n; i++) {
std::cin >> first >> second;
input[i] = { first, second };
}
//...
int total = LENGTH * LENGTH * n; // 모든 색종이의 총 넓이
int overlap = 0; // 겹치는 부분의 넓이
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int leftOverlap = max(input[i].first, input[j].first);
int rightOverlap = min(input[i].first + LENGTH, input[j].first + LENGTH);
int bottomOverlap = max(input[i].second, input[j].second);
int topOverlap = min(input[i].second + LENGTH, input[j].second + LENGTH);
if (leftOverlap < rightOverlap && bottomOverlap < topOverlap) {
int overlapWidth = rightOverlap - leftOverlap;
int overlapHeight = topOverlap - bottomOverlap;
overlap += overlapWidth * overlapHeight;
}
}
}
total -= overlap;
cout << total << endl; // 결과 출력
return 0;
}

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------
<세로 읽기>
#include <iostream>
using namespace std;
char arr[5][15];
int main() {
for (int i = 0; i < 5; i++)
cin >> arr[i];
for (int i = 0; i < 15; i++) {
for (int k = 0; k < 5; k++) {
if(arr[k][i] != NULL)
cout << arr[k][i];
}
}
return 0;
}

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------

<기말고사 평균 조작>

#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
int n, i;
double score;
//사용자 입력(과목 수, 점수)
cin >> n;

 

double arr[n];
 
for(i = 0; i < n; i++){
cin >> score;
arr[i] = score;
}
 
double newSum = 0;
double newArr[n];
double max_score = 0;
//최댓값 찾기(STL 사용)
max_score = *max_element(arr, arr + n);
 
//점수 조작
for(i = 0; i < n; i++){
newArr[i] = (arr[i] / max_score) * 100;
newSum += newArr[i];
}
//새 평균
cout << newSum / n;
return 0;
}

 

'Clipper 스터디' 카테고리의 다른 글

Inflearn 4주차  (0) 2023.11.07
Inflearn 3주차  (0) 2023.11.05
Inflearn 2주차  (0) 2023.10.02
백준_1주차  (0) 2023.09.28
인프런_1주차  (0) 2023.09.28