본문 바로가기

반응형

알고리즘/Hackerrank

(6)
Hackerrank - Taum and B'day 1234567891011long taumBday(long b, long w, long bc, long wc, long z) { long result; if(bc + z
Jumping on the Clouds 1234567891011121314151617// Complete the jumpingOnClouds function below.int jumpingOnClouds(vector c) { int count = 0; int i = 0; while(1) { if(i + 1 >= c.size()) break; if(c[i + 2] != 1) { count++; i += 2; } else if (c[i + 1] == 0){ count++; i++; } } return count;}Colored by Color Scriptercs 예시가 그림까지 너무 잘 나와있어서 모두 가져왔다. 문제는 구름을 뛰어넘는 것을 계산하는 문제이다. 하지만 구름의 종류가 두가지이다. 하나는 일반 구름, 다른 하나는 천둥을 포함하고 있는..
Equalize the Array 12345678910111213141516171819202122232425262728// Complete the equalizeArray function below.int equalizeArray(vector arr) { int maxCount = 1; int maxNum = arr[0]; int tempCount = 1; int tempMax = arr[0]; sort(arr.begin(), arr.end()); for(int i = 0; i = maxCount) { maxNum = tempMax; maxCount = tempCount; } } else { tempCount = 1; tempMax = arr[i + 1]; } } return arr.size() - maxCount; } Colored b..
ACM ICPC Team 123456789101112131415161718192021222324252627282930// Complete the acmTeam function below.vector acmTeam(vector topic) { int maxCount = 0, maxTeams = 0; for(int i = 0; i
A very big sum 123456789101112131415161718import java.io.*;import java.util.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner sc = new Scanner(System.in); long sum = 0; int n = sc.nextInt(); for(int i=0;i
Compare the Triplets 12345678910111213141516171819202122232425262728293031323334353637383940import java.io.*;import java.util.*;import java.text.*;import java.math.*;import java.util.regex.*; public class Solution { static int[] solve(int a0, int a1, int a2, int b0, int b1, int b2){ // Complete this function int[] result = new int[2]; result[0] = result[1] = 0; if(a0 b0) result[0]++; if(a1 b1) result[0]++; if(a2 b2)..