Loading...

[swexpert] 2001. 파리퇴치 (python, java, D2)

현재 위치로 부터 m칸의 크기 안에 있는 위치의 값들을 모두 더해준다 모든 위치를 검사해준다 범위는 전체 배열 길이-m까지 시작위치로 잡고 해당 위치에서 가로 세로 현재위치+m위치까지 검사해준다 1. 파이썬 풀이 t=int(input()) for i in range(1,t+1): result = 0 n,m=map(int,input().split()) arr=[] for _ in range(n): a=list(map(int,input().split())) arr.append(a) for y in range(0,n-m+1): //현재 위치, 여기서부터 m칸을 검사하므로 인덱스가 넘어가지 않게 주의 for x in range(0,n-m+1): sum=0 for yy in range(y,y+m): // 현재 위..

[swexpert] 2005. 파스칼의 삼각형 (python, java)

1 1 1 1 2 1 에서 dp의 인덱스는 j,k가 00 10 11 20 21 22 30 31 32 33 이렇게 된다 k(행)이 0이거나 j==k인 경우 1이고 아닌 경우 dp[j-1][k-1]+dp[j-1][k] 이다 21 위치에 있는 수의 경우 10에 있는 수와 11에 있는 수를 더한다 1. 파이썬 풀이 t=int(input()) for i in range(1,t+1): n=int(input()) print(f'#{i}') dp=[] for j in range(n): arr=[] for k in range(j+1): if k==0 or k==j: arr.append(1) print(1,end=' ') else: arr.append(dp[j-1][k-1]+dp[j-1][k]) print(dp[j-1][..

[swexpert] 2007. 패턴 마디의 길이 (python, java, d2)

조건이 좀 부족하긴 한데 이 문제의 경우 반복되는 문자가 등장하는 대로 바로 반환하면 된다 KK 이건 K가 반복되어 바로 1을 반환하면 된다. 최대 10글자이니 10번만 검사하면 된다 1. 파이썬 풀이 for i in range(int(input())): s=input() for j in range(1,10): if s[:j]==s[j:2*j]: print(f'#{i+1} {j}') break 2. 자바 풀이 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); sc.nextLine(); for (i..

[swexpert] 1926번 간단한 369게임 (python, java, D2)

1. python 풀이 방금 전 다른 문제 풀면서 count메소드를 알아서 활용했다 str로 문자열로 변환해서 3, 6, 9 문자의 개수를 세준 뒤 출력해준다 n=int(input()) for x in range(1,n+1): x=str(x) sum=0 sum+=x.count('3') sum+=x.count('6') sum+=x.count('9') if sum!=0: print('-'*sum,end=' ') else: print(x,end=' ') 2. JAVA 풀이 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc..

[swexpert] 1204. 최빈수 구하기 (python, java)

1. python 풀이 일단 개수를 반환해주는 Counter로 구했는데 arr.count(x)로 해서 찾아도 되었을 듯 하다 * 등장 개수가 같다면 더 큰 점수로 해줘야한다. 가장 큰 개수만을 구한다면 most_common을 쓰면 되는데 이 부분 때문에 for문을 한 번 더 돌아줬다 from collections import Counter t=int(input()) for _ in range(1,t+1): n=int(input()) arr=list(map(int,input().split())) counter=Counter(arr) max_cnt,letter=-1,-1 for x in counter: if counter[x]==max_cnt: if x>letter: letter=x if counter[x]..

[swexpert] 2047. 신문 헤드라인 (D1, python, java)

1. 파이썬 풀이 s=input() converted=[x.upper() for x in s] print(''.join(converted)) 2. 자바 풀이 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.next(); System.out.println(s.toUpperCase()); sc.close(); } }

[swexpert] 2046. 스탬프 찍기 (python, java, D1 )

1. 파이썬 풀이 n=int(input()) print(n*'#') 2. 자바 풀이 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=""; for (int i = 0; i < n; i++) { s+="#"; } System.out.println(s); sc.close(); } }

[swea] 2056. 연월일 달력 (python, java , D1)

문제풀이 언어를 파이썬으로 바꾼 이후로 쉬운 문제부터 다시 연습하고 있다 swea1, 2 부터 다 풀려고 한다 달력 일자 별로 배열에 담아 푸는 방법도 있는데 그게 더 나을 것 같다 1. python 풀이 t=int(input()) for i in range(t): print('#%s' %(i+1),end=' ') date=input() year=int(date[:4]) month=int(date[4:6]) dd=int(date[6:]) if month 12: print(-1) continue if month in [1,3,5,7,8,10,12]: if dd 31: print(-1) continue if month ==2: if dd28: print(-1) continue if month in [4,6,..

[백준] 15686번 치킨배달 (시뮬, bfs, 파이썬, java)

www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net 1. python 풀이 from collections import deque import math from itertools import combinations chicken,house=[],[] n,m=map(int,input().split()) for y in range(n): temp=list(map(int,input().split())) for x in range(len(temp))..

[백준] 1260번 bfs와 dfs (python, java)

1. python import collections import sys sys.setrecursionlimit(2000) def dfs(x): visited[x]=True print(x,end=' ') for y in sorted(dict[x]): if not visited[y]: dfs(y) def bfs(x): visited[x]=True dq=collections.deque() dq.append(x) while dq: cur=dq.popleft() print(cur,end=' ') for y in sorted(dict[cur]): if not visited[y]: visited[y]=True dq.append(y) n,m,v=map(int,sys.stdin.readline().split()) dic..