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

16-wnsmir #66

Merged
merged 1 commit into from
Feb 2, 2025
Merged

16-wnsmir #66

merged 1 commit into from
Feb 2, 2025

Conversation

wnsmir
Copy link
Collaborator

@wnsmir wnsmir commented Jan 26, 2025

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

p.113 ๋‘๋ฒˆ์จฐ ๊ตฌํ˜„๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
๋ฌธ์ œ
์ •์ˆ˜ N์ด ์ž…๋ ฅ๋˜๋ฉด 00์‹œ 00๋ถ„ 00์ดˆ ๋ถ€ํ„ฐ N์‹œ 59๋ถ„ 59์ดˆ๊นŒ์ง€ ๋ชจ๋“  ์‹œ๊ฐ์ค‘ 3์ด ํ•˜๋‚˜๋ผ๋„ ๋“ค์–ด๊ฐ„ ์‹œ๊ฐ์˜ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜์‹œ์˜ค.
์˜ˆ๋ฅผ๋“ค์–ด N์ด 1์ด๋ผ๋ฉด 1์‹œ 59๋ถ„ 59์ดˆ๊นŒ์ง€ 3์ด ํฌํ•จ๋œ ๋ชจ๋“  ์‹œ๊ฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๊ฒƒ.

์˜ˆ์‹œ์ž…๋ ฅ
5
์˜ˆ์‹œ์ถœ๋ ฅ
11475

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

10min

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๊ฐ„๋‹จํ•˜๊ฒŒ 3์ค‘๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๊ตฌํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ฒซ๋ฒˆ์งธ ๋ฐ˜๋ณต๋ฌธ์€ ์‹œ๊ฐ„์ด ์ •ํ•ด์ ธ์žˆ์œผ๋ฏ€๋กœ N+1๋ฒˆ ๋ฐ˜๋ณต, ๋‚˜๋จธ์ง€๋Š” 0๋ถ€ํ„ฐ 59์”ฉ ๋ถ„ ์ดˆ๋ฅผ ๋ฐ˜๋ณตํ•ด์ค๋‹ˆ๋‹ค.
๋งˆ์ง€๋ง‰ ๋ฐ˜๋ณต๋ฌธ์—์„œ ์‹œ ๋ถ„ ์ดˆ ํ•˜๋‚˜๋ผ๋„ 3์ด ํฌํ•จ๋˜์–ด์žˆ์œผ๋ฉด sum์„ += 1 ํ•ด์ค๋‹ˆ๋‹ค.

n = int(input())
sum = 0

for i in range(n + 1):
    for j in range(60):
        for k in range(60):
            if '3' in str(i) or '3' in str(j) or '3' in str(k):
                sum += 1

print(sum)

Copy link
Collaborator

@g0rnn g0rnn left a comment

Choose a reason for hiding this comment

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

์ด๋Ÿฐ ๋ฌธ์ œ๊ฐ€ ์ •๋ง ์ž์ฃผ ๋‚˜์˜ค๋Š” ๊ฑฐ ๊ฐ™๋„ค์š”. ๋งค๋ฒˆ ์ˆซ์ž๋กœ ํ’€์ง€ ๋ฌธ์ž๋กœ ํ’€์ง€ ๊ณ ๋ฏผ๋ฉ๋‹ˆ๋‹ค. ๊ทผ๋ฐ ๋Š˜ ์ˆซ์ž๋กœ ํ‘ธ๋Š”๊ฒŒ ๋” ์˜ˆ์˜๊ณ  ๋น ๋ฅด๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์š”.

์ œ ์ฝ”๋“œ๋Š” ์‚ด์ง ๊ธธ์ง€๋งŒ ์ค€์šฉ๋‹˜ ์ฝ”๋“œ๊ฐ€ ์งง๊ณ  ์ •๋ง ์ด์˜๋„ค์š”. ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค.

public class Solution16 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int hh = 0, mm = 0, ss = 0;
        int cnt = 0;
        while(!(hh == n && mm == 59 && ss == 59)) {
            ss++;
            if(ss > 59) {
                ss = 0;
                mm++;
            }
            if(mm > 59) {
                mm = 0;
                hh++;
            }
            if(hh > 23) break;

            if(String.valueOf(hh).contains("3")
            || String.valueOf(mm).contains("3")
            || String.valueOf(ss).contains("3")) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

}

Copy link
Collaborator

@kangrae-jo kangrae-jo left a comment

Choose a reason for hiding this comment

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

3์ค‘ for๋ฌธ์œผ๋กœ ํ‘ธ๋Š” ๋ฐฉ์‹์ด ๊ฐ„๋‹จํ•˜๊ณ  ์ข‹์€ ๊ฒƒ ๊ฐ™๋„ค์š”.
์ค€์šฉ๋‹˜ ๋ฌธ์ œ ์ฝ์œผ๋ฉด์„œ ์•„๋ž˜์— ์Šคํฌ๋ฅผ ๋ด๋ฒ„๋ ค์„œ....
๊ฝค ๋น ๋ฅด๊ฒŒ ๊ตฌํ˜„์„ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!

์ข‹์€ ๋ฌธ์ œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

#include <iostream>

using namespace std;

bool isContains(string time) {
    for (char t : time) if (t == '3') return true;
    return false;
}

int main() {
    int N;
    cin >> N;

    int cnt = 0;
    for (int h = 0; h <= N; h++) {
        for (int m = 0; m < 60; m++) {
            for (int s = 0; s < 60; s++) {
                if (isContains(to_string(h)) 
                || isContains(to_string(m)) 
                || isContains(to_string(s))) cnt++;
            }
        }
    }
    cout << cnt;
    
    return 0;
}

@wnsmir wnsmir merged commit 63761a9 into main Feb 2, 2025
1 check passed
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.

3 participants