Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-9kyo-hwang #1

Merged
merged 4 commits into from
Nov 9, 2023
Merged

1-9kyo-hwang #1

merged 4 commits into from
Nov 9, 2023

Conversation

9kyo-hwang
Copy link
Collaborator

@9kyo-hwang 9kyo-hwang commented Nov 7, 2023

πŸ”— 문제 링크

[κΈ°λ³Έ] 행볡은 μ„±μ μˆœμ΄ μ•„λ‹ˆμž–μ•„μš”.

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

1λΆ„

✨ μˆ˜λ„ μ½”λ“œ

  • νŠΉλ³„ν•œ μžλ£Œκ΅¬μ‘°λ‚˜ μ•Œκ³ λ¦¬μ¦˜μ„ μ‚¬μš©ν•  ν•„μš” 없이, λ¬Έμ œμ—μ„œ μš”κ΅¬ν•œ μ‘°κ±΄λŒ€λ‘œ μ°¨κ·Όμ°¨κ·Ό 계산해주면 λ˜λŠ” κ°„λ‹¨ν•œ λ¬Έμ œμ΄λ‹€. ν•˜λ‚˜μ”© ν›‘μ–΄λ³΄μž.
int t; cin >> t;
bool answer = true;
  • λ¨Όμ € ꡬ름이가 λ“£λŠ” μˆ˜μ—… 개수 tλ₯Ό μž…λ ₯λ°›λŠ”λ‹€.

  • 그리고 ꡬ름이가 'A+' 쑰건을 μΆ©μ‘±ν–ˆλŠ” 지, μΆ©μ‘±ν•˜μ§€ λͺ»ν–ˆλŠ” 지λ₯Ό λ‚˜νƒ€λ‚΄λŠ” boolean λ³€μˆ˜ answerλ₯Ό μ„ μ–Έ, true둜 μ •μ˜ν•œλ‹€.

    • μ°Έκ³ : cin은 c++μ—μ„œ ν‚€λ³΄λ“œλ‘œλΆ€ν„° μž…λ ₯λ°›λŠ” ν•¨μˆ˜μ΄λ©°, C의 scanf()와 λ™μΌν•œ 역할을 μˆ˜ν–‰ν•œλ‹€.
  • μˆ˜μ—… 개수 t만큼 λ°˜λ³΅ν•˜λ©΄μ„œ, 각 κ³Όλͺ© λ³„λ‘œ A+ 기쀀을 μΆ©μ‘±ν•˜λŠ” 지 κ²€μ‚¬ν•˜μž.

while(t--) {
  ...
}

// λ™μΌν•œ κΈ°λŠ₯을 ν•˜λŠ” forλ¬Έ μ½”λ“œ
for(int i = 0; i < t; i++) {
  ...
}
  • 이제 각 μˆ˜μ—… λ³„λ‘œ 쑰건을 ν™•μΈν•΄λ³΄μž.
int l, s, n, k, m;  // 학생 수, λ“±μˆ˜, A+ λΉ„μœ¨, μˆ˜ν–‰ 평가 개수, 과락 점수
cin >> l >> s >> n >> k >> m;

vector<int> v(k); // μˆ˜ν–‰ 평가 k개의 각 점수
for(int &i : v) cin >> i;
  • μš°μ„  학생 수, λ“±μˆ˜, A+ λΉ„μœ¨, μˆ˜ν–‰ 평가 개수, 과락 점수λ₯Ό μž…λ ₯λ°›κ³  k개의 μˆ˜ν–‰ 평가 점수λ₯Ό μ΄μ–΄μ„œ μž…λ ₯λ°›λŠ”λ‹€.
    • μ°Έκ³ : vectorλŠ” "κ°€λ³€ λ°°μ—΄"을 μ˜λ―Έν•œλ‹€. λ³€μˆ˜λ₯Ό μ„ μ–Έν•  λ•Œ 개수 kλ₯Ό λ„˜κ²¨μ£Όλ©΄ 기본적으둜 크기가 k인 배열을 생성해쀀닀. μ•„λž˜μ™€ λ™μΌν•˜λ‹€κ³  μƒκ°ν•˜λ©΄ λœλ‹€.
int v[k];
  • vector λ³€μˆ˜ λ°‘μ˜ for문은 k개 만큼 값을 μž…λ ₯λ°›λŠ” μ½”λ“œλ‘œ, μ•„λž˜μ™€ λ™μΌν•˜λ‹€.
for(int j = 0; j < k; j++) {
  cin >> v[j];
}
  • 이제 이 κ³Όλͺ©μ—μ„œ 받은 λ“±μˆ˜κ°€ A+ λΉ„μœ¨μ— ν¬ν•¨λ˜λŠ”μ§€, 각 μˆ˜ν–‰ 평가가 과락 점수λ₯Ό λ„˜κ²ΌλŠ” 지 ν™•μΈν•΄λ³΄μž.
if(s >= l * (double)n / 100) {
  result = false;
} else {
  for(const int i : v) {
    if(i <= m) {
      result = false;
      break;
    }
  }
}
  • 이 κ³Όλͺ©μ„ μˆ˜κ°•ν•œ 학생 수 l에닀가 A+ λΉ„μœ¨μ„ λ‚˜νƒ€λ‚΄λŠ” n을 κ³±ν•˜λ©΄, A+에 ν•΄λ‹Ήν•˜λŠ” 학생 μˆ˜κ°€ λ‚˜νƒ€λ‚œλ‹€. 이 λ•Œ n μžμ²΄λŠ” %수치λ₯Ό λ‚˜νƒ€λ‚΄λ―€λ‘œ 100으둜 λ‚˜λˆ  0.?으둜 ν‘œν˜„ν•œλ‹€.

    • λ§Œμ•½ λ“±μˆ˜ sκ°€ A+ 학생 μˆ˜λ³΄λ‹€ '크닀면', A+ μ•ˆμ— 듀지 λͺ»ν–ˆλ‹€λŠ” λœ»μ΄λ―€λ‘œ resultλ₯Ό false둜 λ°”κΏ”μ€€λ‹€.
  • λ‹€μŒμœΌλ‘œ 각 μˆ˜ν–‰ 평가 점수λ₯Ό ν™•μΈν•˜κΈ° μœ„ν•΄, μˆ˜ν–‰ 평가 μ μˆ˜κ°€ λ‹΄κΈ΄ λ°°μ—΄ vλ₯Ό μˆœνšŒν•œλ‹€.

    • λ§Œμ•½ μˆ˜ν–‰ 평가 점수 쀑 'ν•˜λ‚˜λΌλ„' 과락 점수 m보닀 μž‘κ±°λ‚˜ κ°™λ‹€λ©΄, μ—­μ‹œ A+을 받을 수 μ—†μœΌλ―€λ‘œ resultλ₯Ό false둜 λ°”κΏ”μ€€λ‹€.
  • 반볡문이 λͺ¨λ‘ 끝났닀면, λ§ˆμ§€λ§‰μœΌλ‘œ κ²°κ³Όλ₯Ό 좜λ ₯ν•΄μ£Όμž.

cout << result;
  • μœ„ 반볡문 μˆ˜ν–‰μ΄ λλ‚¬μŒμ—λ„ resultκ°€ μ—¬μ „νžˆ true라면, κ΅¬λ¦„μ΄λŠ” "λͺ¨λ“  κ³Όλͺ©μ—μ„œ A+을 λ°›μ•˜μŒ"을 μ˜λ―Έν•˜κ²Œ λœλ‹€. λ”°λΌμ„œ true, 즉 1을 좜λ ₯ν•˜κ²Œ λœλ‹€.

  • μ•„λ‹ˆλΌλ©΄ false, 즉 0을 좜λ ₯ν•˜κ²Œ λœλ‹€.

    • μ°Έκ³ : C++μ—μ„œλŠ” bool λ³€μˆ˜λ₯Ό 좜λ ₯ν•˜λ©΄ trueλŠ” 1, falseλŠ” 0으둜 μžλ™μœΌλ‘œ 좜λ ₯ν•œλ‹€.
  • 전체 μ½”λ“œλŠ” μ•„λž˜μ™€ κ°™λ‹€.

#include <iostream>
#include <vector>

using namespace std;

int main() {
	int t; cin >> t;
	bool result = true;
	while(t--) {
		int l, s, n, k, m;  // 학생 수, λ“±μˆ˜, A+ λΉ„μœ¨, μˆ˜ν–‰ 평가 개수, 과락 점수
		cin >> l >> s >> n >> k >> m;
		vector<int> v(k); // μˆ˜ν–‰ 평가 k개의 각 점수
		for(int &i : v) cin >> i;
		
		if(s >= l * (double)n / 100) {
			result = false;
		} else {
			for(const int i : v) {
				if(i <= m) {
					result = false;
					break;
				}
			}
		}
	}
	
	cout << result;
	return 0;
}

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

  • μ—†μŒ!

@Munbin-Lee
Copy link
Member

```cpp
μ½”λ“œ
```
μ½”λ“œ μ΄λ ‡κ²Œ μ“°μ‹œλ©΄ μ½”λ“œ ν•˜μ΄λΌμ΄νŠΈ μ μš©λΌμš”!

Comment on lines +18 to +25
} else {
for(const int i : v) {
if(i <= m) {
result = false;
break;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else 쓰지 μ•Šκ³ , μœ— λΆ€λΆ„μ—μ„œ 쑰건 λ§Œμ‘±ν•˜λ©΄ returnμ΄λ‚˜ break둜 λŠμ–΄μ£ΌλŠ” 건 μ–΄λ–¨κΉŒμš”?

μŠ€μ½”ν”„κ°€ λ„ˆλ¬΄ κΉŠμ–΄μ§€λŠ” 것 κ°™μ•„μš”!

Copy link
Collaborator

@Dolchae Dolchae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€!!
vectorλ³€μˆ˜λŠ” 처음 λ“€μ–΄λ³΄λŠ” κ°œλ…μ΄μ—ˆλŠ”λ° μ•žμœΌλ‘œλ„ μ„ λ°°λ‹˜ μ½”λ“œ ν†΅ν•΄μ„œ 많이 λ°°μ›Œκ°ˆκ²Œμš”β˜ΊοΈ

@xxubin04
Copy link
Member

xxubin04 commented Nov 9, 2023

μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€!πŸ‘
1λΆ„λ§Œμ— ν‘Έμ…¨λ‹€λ‹ˆ λŒ€λ‹¨ν•˜μ‹­λ‹ˆλ‹€...😁
cin, vector... μƒˆλ‘œμš΄ 것듀을 많이 λ°°μ›Œκ°‘λ‹ˆλ‹€!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants