목록코딩테스트 (73)
bdfgdfg
#include #include #include using namespace std; int solution(vector board, vector moves) { int answer = 0; stack s; //N*N크기 int boardSize = board.size(); int len = moves.size(); int firstIndex, i, j; for (i = 0; i < len; ++i) // 이건 맞음. { int x = moves[i] - 1; // x값은 고정 y값만 이동 for (j = 0; j < boardSize; ++j) { if (board[j][x] != 0) { if (!s.empty()) { if (s.top() == board[j][x]) { s.pop(); answer..
#include #include using namespace std; bool IsPrime(int num) { for(int prime = 2; prime < num; ++prime) { if(num % prime == 0) return false; } return true; } int solution(vector nums) { int answer = 0; int len = nums.size(); // 2 3 5 7 int i,j,k,num; for(i = 0; i < len; ++i) { for(j = i + 1; j < len; ++j) { for(k = j + 1; k < len; ++k) { if(IsPrime(num = nums[i] + nums[j] + nums[k])) ++answer; }..
#include #include using namespace std; int solution(int n) { int answer = 0; for(int i = 2; i < n; ++i) { if(n % i == 1) { answer = i; break; } } return answer; }
#include #include using namespace std; int CalDistance(pair& handPos, pair& targetPos) { int dist = (handPos.first > targetPos.first) ? handPos.first - targetPos.first : targetPos.first - handPos.first; if (handPos.second == 1) // 2580 라인일때 return dist; return dist + 1; } void CheckHand(string& answer, pair& leftHandPos, pair& rightHandPos, pair targetPos,string& hand) { int left = CalDistance(l..