본문 바로가기

분류 전체보기

(64)
[백준] 1009: 분산처리 자꾸 틀렸다고 나오는데, 나머지가 0으로 떨어지면 0이 아니라 10을 출력해야 한다. 내가 짠 코드 #include using namespace std; int main(void){ int N,i,j,a,b,value; scanf("%d",&N); for(i=0;i
[백준] 1032: 명령 프롬프트 string문자열 입력 받을 때는 이전에 줄바꿈을 받지 않도록 하기 위해 scanf("%d\n"~)까지 잘 해주는 것과, getline으로 줄 단위로 받고, 특정 위치의 내용을 바꾸기 위해서는 replace 사용해서 바꾸는 것. 내가 짠 코드 #include #include using namespace std; int main(void){ int N,i,length,j; char input[55]; string list; string ans; scanf("%d\n",&N); for(i=0;i
[백준] 1026번: 보물 C++에서 벡터 sorting하기. 필요한 라이브러리는 #include Sort는 다음과 같이 정의. sort(시작, 끝, 비교함수). 보통은 마지막을 생략하면(비교함수) 오름차순으로 정렬된다. 만약 내림차순으로 하고 싶다면 비교함수를 정의해주면 된다. 내가 짠 코드 #include #include #include using namespace std; bool desc(int a, int b){ return a>b; } int main(void){ int N; vector A, B; int i,value,S=0; scanf("%d",&N); for(i=0;i
[LeetCode] Arithmetic SlicesSolution 내가 짠 코드 class Solution { public: int numberOfArithmeticSlices(vector& A) { if(A.size()
[LeetCode] Linked List Cycle 리트코드 하기 전에는 몰랐던 링크드 리스트 나오면 꼭 생각해야하는 fast/slow (runner/walker) 방식. 알아두면 유용. 내가 짠 코드 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: bool hasCycle(ListNode *head) { ListNode *walker, *runner; walker = head; runner = head; while(runner!=NULL && runner->next!=NULL){ walker = walker->..
[LeetCode] Number of 1 Bits 비트연산해서 1이 몇 개 있는지 판별하는 코드. 한 번 풀어놓으면 유용하다. 자주 나오지는 않지만 비트연산 나오면 알고 있으면 유용하게 쓰인다고 생각. 비트연산이 잘 안나와 나오기만 하면 죄다 낯설어서 그렇지... 내가 짠 코드 class Solution { public: int hammingWeight(uint32_t n) { int count =0; for(int i=0;i> 1; } return count; } }; leetcode.com/explore/challenge/card/february-leetcoding-challenge-2021/584/week-1-february-1st-february-7th/3625/
[백준] 14499번: 주사위 굴리기 내가 짠 코드 #include #include #include using namespace std; // N * M 인 지도 //지도 좌표(r, c) r: 북쪽으로부터, c : 서쪽으로부터 /*r r r r rccccc */ //1 동쪽 2 서쪽 3 북쪽 4 남쪽 // 0,1 0,-1 -1,0 1,0 // -> dice_map(N); for(i=0;i
[백준] 14503번: 로봇 청소기 내가 짠 코드 #include #include #include #include using namespace std; // d가 0 1 2 3 북동남서 // 북 // 서 동 // 남 //현재방향 기준 왼쪽방향 /* 현재위치가 (r,c) 0(북) : 서쪽방향 (r,c-1) 3 후진 : r+1,c : 3 1(동) : 북쪽방향 (r-1,c) 0 후진 : r, c-1 : 0 2(남) : 동쪽방향 (r,c+1) 1 후진 : r-1,c : 1 3(서) : 남쪽방향 (r+1,c) 2 후친 : r, c+1 : 2 */ int N,M; int totalClean=0; int movement[4][3]={{0,-1,3},{-1,0,0},{0,1,1},{1,0,2}}; void step2(vector < vector < in..