π 곡λΆνλ μ§μ§μνμΉ΄λ μ²μμ΄μ§?
[μ΄κ²μ΄ μ½λ© ν μ€νΈλ€ with Python]_15_ꡬν λ¬Έμ νμ΄ λ³Έλ¬Έ
[μ΄κ²μ΄ μ½λ© ν μ€νΈλ€ with Python]_15_ꡬν λ¬Έμ νμ΄
μ§μ§μνμΉ΄ 2022. 1. 31. 22:53220131 μμ±
<λ³Έ λΈλ‘κ·Έλ γμ΄κ²μ΄ μ·¨μ μ μν μ½λ© ν μ€νΈλ€γ μ youtubeλ₯Ό μ°Έκ³ ν΄μ 곡λΆνλ©° μμ±νμμ΅λλ€>
https://www.youtube.com/watch?v=QhMY4t2xwG0&list=PLVsNizTWUw7H9_of5YCB0FmsSc-K44y81&index=15
< λ¬Έμ 1 > μκ°
: μ μ N μ΄ μ λ ₯λλ©΄ 00μ 00λΆ 00μ΄λΆν° Nμ 59λΆ 59μ΄κΉμ§μ λͺ¨λ μκ° μ€μμ 3μ΄ νλλΌλ ν¬ν¨λλ
λͺ¨λ κ²½μ°μ μλ₯Ό ꡬνλΌ
: κ°λ₯ν λͺ¨λ μκ°μ κ²½μ°λ₯Ό νλμ© λͺ¨λ μΈμ ν μ μμ
: μμ νμ (Brute Forcing) -> κ°λ₯ν κ²½μ°μ μλ₯Ό λͺ¨λ κ²μ¬ν΄λ³΄λ νμ λ°©λ²
- python
a = int(input())
cnt = 0
for i in range(a+1) :
for j in range(60) :
for k in range(60) :
if '3' in str(i) + str(j) + str(k):
cnt += 1
print(cnt)
- c++
#include <bits/stdc++.h>
using namespace std;
int h, cnt;
bool check(int h, int m, int s) {
if (h % 10 == 3 || m / 10 == 3 || m % 10 == 3 || s / 10 == 3 || s % 10 == 3)
return true;
return false;
}
int main(void) {
cin >> h;
for (int i = 0; i <= h; i ++) {
for (int j = 0; j <= 60; j ++) {
for (int k = 0; k <= 60; k ++) {
if (check(i, j, k))
cnt ++;
}
}
}
cout << cnt << '\n';
return 0;
}
- java
import java.util.*;
public class Main {
public static boolean check(int h, int m, int s) {
if (h % 10 == 3 || m / 10 == 3 || m % 10 == 3 || s / 10 == 3 || s % 10 == 3)
return true;
return false;
}
public static void(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int cnt = 0;
for (int i = 0; i <= h; i ++) {
for (int j = 0; j <= 60; j ++) {
for (int k = 0; k <= 60; k ++) {
if (check(i, j, k))
cnt ++;
}
}
}
System.out.println(cnt);
}
}
< λ¬Έμ 2 > μμ€μ λμ΄νΈ
: μμ€μ μμ 8 x 8 μ’ν νλ©΄
: λμ΄νΈλ μ΄λν λ L μ ννλ‘λ§ μ΄λ
- μνμΌλ‘ λμΉΈ μ΄λ -> μμ§μΌλ‘ νμΉΈ
- μμ§μΌλ‘ λμΉΈ μ΄λ -> μνμΌλ‘ νμΉΈ
: λμ΄νΈμ μμΉκ° μ£Όμ΄μ‘μ λ λμ΄νΈκ° μ΄λν μ μλ κ²½μ°μ μ μΆλ ₯
: ν μμΉλ 1 ~ 8
: μ΄ μμΉλ a ~ h
- python
data = input()
row = int(data[1])
column = int(ord(data[0])) - int(ord('a')) + 1
steps = [(-2, -1), (-1, -2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)]
result = 0
for step in steps :
next_row = row + step[0]
next_column = column + step[1]
if next_row >= 1 and next_row <= 8 and next_column >= 1 and next_column <= 8 :
result +=1
print(result)
- c++
#include <bits/stdc++.h>
using namespace std;
string inputData;
int dx[] = {-2, -1, 1, 2, 2, 1, -1, -1};
int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};
int main(void) {
cin >> inputData;
int row = inputData[1] - '0';
int column = inputData[0 - 'a' + 1;
int result = 0;
for (int i = 0; i <8; i++) {
int nextRow = row + dx[i];
int nextColumn = column + dy[i];
if (nextRow >= 1 && nextRow <= 8 && nextColumn >= 1 && nextColumn <= 8) {
result += 1;
}
}
cout << result << '\n';
return 0;
}
- java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String inputData = sc.NextLine();
int row = inputData.charAt(1) - '0';
int column = inputData.charAt(0) - 'a' + 1;
int[] dx = {-2, -1, 1, 2, 2, 1, -1, -2};
int[] dy = {-1, -2, -2, -1, 1, 2, 2, 1};
int result = 0;
for (int i = 0; i < 8; i ++ ) {
int nextRow = row + dx[i];
int nextColumn = column + dy[i];
if (nextRow >= 1 && nextRow <= 8 && nextColumn >= 1 && nextColumn <= 8) {
result += 1;
}
}
System.out.println(result);
}
}
< λ¬Έμ 3 > λ¬Έμμ΄ μ¬μ λ ¬
: μνλ²³ λλ¬Έμμ μ«μ (0~9)λ‘λ§ κ΅¬μ±λ λ¬Έμμ΄μ΄ μ λ ₯μΌλ‘ μ£Όμ΄μ§λ€
: λͺ¨λ μνλ²³μ μ€λ¦μ°¨μ μ λ ¬ ν λͺ¨λ μ«μλ₯Ό λν κ°μ μ΄μ΄μ μΆλ ₯
: λ¬Έμλ₯Ό νλμ© νμΈ
- μ«μμΈ κ²½μ° λ°λ‘ ν©κ³ κ³μ°
- μνλ²³μ λ³λμ 리μ€νΈμ μ μ₯
- python
data = input()
alpha = []
sum = 0
for i in data :
if i.isalpha() :
alpha.append(i)
else :
sum += int(i)
alpha.sort()
if sum != 0 :
alpha.append(str(sum))
print(''.join(alpha))
- c++
#include <bits/stdc++.h>
using namespace std;
string str;
vector<char> result;
int sum = 0;
int main(void) {
cin >> str;
for (int i = 0; i< str.size(); i++) {
if (isalpha(str[i])) {
result.push_back(str[i]);
}
else {
sum += str[i] - '0'
}
}
sort(result.begin(), result.end());
for (int i = 0; i<result.size(); i++) {
cout << result[i];
}
if (value !=0)
cout << value;
cout << '\n';
}