목록코딩테스트/Python (24)
Star_project
2. 숫자만 추출 import sys sys.stdin=open("pythonalgorithm/섹션 3/2. 숫자만 추출/in1.txt","rt") a=input() res=cnt=0 for i in a: if i.isdecimal(): res=res*10+int(i) print(res) for i in range(1,res+1): if res%i==0: cnt+=1 print(cnt) isdecimal() Definition and Usage The isdecimal() method returns True if all the characters are decimals (0-9). This method is used on unicode objects. 출처 : https://www.w3schools.co..
1.회문 문자열 검사 import sys sys.stdin=open("pythonalgorithm/섹션 3/1. 회문 문자열 검사/in1.txt","rt") n=int(input()) for i in range(n): x=input() x=x.upper() for j in range(len(x)//2): if x[j]!=x[-j-1]: print("#%d NO" %(i+1)) break else: print("#%d YES" %(i+1)) x=input() 하면 됨!!
import sys sys.stdin=open("pythonalgorithm/섹션 2/10. 점수 계산/in2.txt","rt") n=int(input()) a=list(map(int,input().split())) score=ch=0 for x in a: if x==1 and ch==0: score+=1 ch+=1 elif x==1 and ch>0: score+=(1+ch) ch+=1 else: ch=0 print(score) 내가 푼 풀이 import sys sys.stdin=open("pythonalgorithm/섹션 2/10. 점수 계산/in2.txt","rt") n=int(input()) a=list(map(int,input().split())) score=ch=0 for x in a: if x..
import sys sys.stdin=open("pythonalgorithm/섹션 2/9. 주사위 게임/in5.txt","rt") n=int(input()) res=0 for _ in range(n): tmp=list(map(int,input().split())) tmp.sort() a,b,c=tmp if a==b and b==c: money=10000+1000*a elif a==b or a==c: money=1000+100*a elif b==c: money=1000+100*b else: money=100*c if money>res: res=money print(res)
import sys from sklearn.utils import resample sys.stdin=open("pythonalgorithm/섹션 2/8. 뒤집은 소수/in5.txt","rt") n=int(input()) a=list(map(int, input().split())) def reverse(x): res=0 while x>0: t=x%10 res=res*10+t x=x//10 return res def isPrime(x): if x==1: return False for i in range(2, x//2+1): if x%i==0: return False # false 당하면 if 문 끝남 else: return True # for 문 이 False 안당하고 정상적으로 종료되면 else 문 실행 ..
자릿수 더하기 문제 설명 자연수 N이 주어지면, N의 각 자릿수의 합을 구해서 return 하는 solution 함수를 만들어 주세요. 예를들어 N = 123이면 1 + 2 + 3 = 6을 return 하면 됩니다. 제한사항 N의 범위 : 100,000,000 이하의 자연수 입출력 예Nanswer 123 6 987 24 입출력 예 설명 입출력 예 #1 문제의 예시와 같습니다. 입출력 예 #2 9 + 8 + 7 = 24이므로 24를 return 하면 됩니다. def solution(n): answer = 0 while n>0: answer+=n%10 n=n//10 return answer
7. 소수(에라토스테네스 체) import sys sys.stdin=open("pythonalgorithm/섹션 2/7. 소수(에라토스테네스 체)/in4.txt", 'rt') n=int(input()) ch=[0]*(n+1) cnt=0 for i in range(2,n+1): if ch[i]==0: cnt+=1 for j in range(i, n+1, i): ch[j]=1 print(cnt)
import sys sys.stdin=open("pythonalgorithm/섹션 2/6. 자릿수의 합/in2.txt") n=int(input()) a=list(map(int, input().split())) def digit_sum(x): sum=0 while x>0: sum+=x%10 x=x//10 return sum max=-2147000000 for x in a: tot=digit_sum(x) if max0: sum+=x%10 x=x//10
4.대표값 import sys sys.stdin=open("pythonalgorithm/섹션 2/4. 대표값/in1.txt", "rt") n = int(input()) a=list(map(int, input().split())) ave=round(sum(a)/n) min=2147000000 # 정수형의 가장 큰 값 4byte 32비트 부호 정수형의 최대값 for idx, x in enumerate(a): tmp=abs(x-ave) if tmpscore: score=x res=idx+1 print(ave, res) 2,147,483,647은 컴퓨팅에서 32비트 부호 정수형의 최댓값이기도 하다. 그래서 일반적인 CPU위에서 작동하는 많은 프로그래밍 언어에서 변수 int로 선언될 수 있는 최댓값으로 지정되어 ..
03.K번째 큰 수 import sys sys.stdin=open("/Users/eomminjeong/codingtest/pythonalgorithm/섹션 2/3. k번째 큰 수/in1.txt","rt") n,k=map(int, input().split()) a=list(map(int, input().split())) res=set() #set은 중복을 제거하는 자료구조 # 3개의 자료를 뽑아서 합한 후 res 에 추가 for i in range(n): for j in range(i+1,n): for m in range(j+1,n): res.add(a[i]+a[j]+a[m]) #set은 append 아니고 add #set은 sort 없어서 list 화 시켜야함. res=list(res) res.sort(..