728x90
SMALL

using System;

public class Solution {
    public int solution(int a, int b) {
        int answer = 1;


        while(b % 2 == 0)
        {
            b /= 2;
        }


        while(b % 5 == 0)
        {
            b /= 5;
        }


        if(a % b != 0)
        {
            answer = 2;
        }
        return answer;
    }
}

 

 

자바

 

class Solution {
    public int solution(int a, int b) {
        int answer = 0;

        for (;b%2 == 0;) 
        {
            b = b/2;
        }
        
        for (;b%5 == 0;) 
        {
            b = b/5;
        }

        if ((a/(double)b)%1 == 0) 
        {
            answer = 1;
        } 
        else 
        {
            answer = 2;
        }

        return answer;
    }
}

 

 

class Solution {
    public int solution(int a, int b) {
        int answer = 1;
        int max = 0;
        
        for(int i =1; i<=a; i++)
        {
            if(a%i ==0 && b%i ==0) 
              max= i;
        }

        b /= max;

        while(b>1)
        {
            if(b%2==0)
            {
                b /= 2;
            }
            else if(b%5==0)
            {
                b /= 5;
            }
            else 
            {
                return 2;
            }
        }

        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int chicken) {
        int answer = 0;
        
        for(int i=0;i<6;i++)
        {
            answer += chicken/10;
            chicken = chicken/10 + chicken%10;
        }
        
        return answer;
    }
}

 

 

자바

 

class Solution {
    public int solution(int chicken) {
        int answer = 0;
        
        while (chicken >= 10)
        {
            int service = chicken / 10;
            int nmg = chicken %  10;

            chicken = service + nmg;

            answer += service;

        }

        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(string A, string B) {
        return (B+B).IndexOf(A);
    }
}

 

B string에 B를 한 번더 더해서 A의 문자열을 민 거 같은 효과를 만들고, 그 안에 IndexOf를 사용해서 A가 안에 있는 지 확인 할 수 있다.

using System;
using System.Collections.Generic;

public class Solution {
    public int solution(string A, string B) {
        int answer = 0;
        List<char> q = new List<char>(A);

        for (int i = A.Length - 1; i >= 0; i--)
        {
            if (string.Concat(q) == B)
            {
                return answer;
            }

            q.Insert(0, A[i]);
            q.RemoveAt(q.Count - 1);

            answer++;
        }

        return -1;
    }
}

 

////

///////////////////////

/////

 

using System;

public class Solution {
    public int solution(string A, string B) {
        int answer = -1;
        for (int i = 0; i < A.Length; i++)
        {
            if (A == B)
            {
                return i;
            }
            else
            {
                A = stringShift(A);
            }
        }
        return answer;
    }

    public string stringShift(string s)
    {
        var last = s[s.Length - 1];
        s = s.Remove(s.Length -1, 1);
        s = last.ToString() + s;
        return s;
    }
}

 

 

자바

 

class Solution {
    public int solution(String A, String B) {
        String tempB = B.repeat(2);
        return tempB.indexOf(A);
    }
}

 

 

class Solution {
    public int solution(String A, String B) {
        int answer = 0;
        if(A.equals(B)) return 0;

        while(answer<A.length())
        {
            answer++;
            A = A.substring(A.length()-1) + A.substring(0,A.length()-1);
            
            if(B.equals(A)) 
              break;

        }
        
        if(answer==A.length()) 
          answer = -1;

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int[] sides) {
        int answer = 0;
        
        if(sides[0] > sides[1])
        {
            for(int i=sides[0]-sides[1]+1;i<sides[0]+sides[1];i++)
            {
                answer++;
            }
        }
        else
        {
            for(int j=sides[1]-sides[0]+1;j<sides[1]+sides[0];j++)
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

////

 

 

using System;

public class Solution {
    public int solution(int[] sides) {
        int answer = 0;
        int max = (int)MathF.Max(sides[0], sides[1]);
        int total = sides[0] + sides[1];
        int min = total - max;
        return total-1-max+min;
    }
}

 

 

 

using System;
using System.Linq;
public class Solution {
    public int solution(int[] sides)
        {
            int answer = 0;
            int max = sides.Max();
            int min = sides.Min();

            for (int i = 1; i < max + min; i++)
            {
                if (max < i + min)
                {
                    answer++;
                }
            }
            return answer;
        }
}

 

 

자바

 

 

class Solution {
    public int solution(int[] sides) {
        int cnt = 0;
        for (int i = (sides[0]>sides[1]?sides[0]-sides[1]:sides[1]-sides[0])+1; i < sides[0] + sides[1]; i++)  cnt++;
        return cnt;
    }
}

 

 

class Solution {
    public int solution(int[] sides) {
            int min=Math.min(sides[0], sides[1]);
            int max=Math.max(sides[0], sides[1]);
            int sum=sides[0]+sides[1];
            int answer = 0;

            for(int i=1;i<sum;i++) 
            {
                if(i<=min || i<max)
                {//i가 중간값 또는 최솟값 
                    if(max<min+i) 
                    {
                        answer++;
                    }
                }
                else if(i>=max) {//i가 가장 긴 변이면
                    answer++;
                }
            }
            
            return answer;
        }
    }
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Linq;

public class Solution {
    public int solution(int[,] dots) {
        int answer = 0;
        int[] x = new int[4];
        int[] y = new int[4];
        
        for(int i = 0; i < 4; i++)
        {
            x[i] = dots[i,0];
            y[i] = dots[i,1];
        }
        answer = (x.Max() - x.Min()) * (y.Max() - y.Min());
        return answer;
    }
}

 

 

자바

 

class Solution {
    public int solution(int[][] dots) {
        int answer = 0;
        int tmp = dots[0][0];
        int tmp2 = 0;
        int tmp3 = 0;
        
        for(int i = 1; i<dots.length; i++)
        {
            if(dots[i][0] == tmp)
            {
                tmp2 = Math.abs(dots[i][1] - dots[0][1]);
            }
            else
            {
                tmp3 = Math.abs(dots[i][0] - dots[0][0]);
            }
        }
        
        answer = tmp2 * tmp3;
        return answer;
    }
}

 

 

import java.util.*;

class Solution {
    public int solution(int[][] dots) {
        int answer = 0;

        int[] dot = dots[0];

        for(int i =0; i<dots.length; i++)
        {
            int x = dots[i][0];
            int y = dots[i][1];

            if(dot[0]!=x && dot[1]!=y)
            {
                answer = Math.abs(x-dot[0]) * Math.abs(y-dot[1]);
                break;
            }
        }

        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public string solution(string[] id_pw, string[,] db) {
        string answer = "";
        
        for(int i = 0; i < db.GetLength(0); i++)
        {
            if(id_pw[0] == db[i,0])
            {
                if(id_pw[1] == db[i,1])
                {
                    answer = "login";
                }
                else
                {
                    answer = "wrong pw";
                }
                break;
            }
            else
            {
                answer = "fail";
            }
        }
        return answer;
    }
}

 

 

자바

 

 

class Solution {
    public String solution(String[] id_pw, String[][] db) {
        String answer = "";

        for(int i = 0; i < db.length; i++)
        {
            if(db[i][0].equals(id_pw[0]))
            {
                if(db[i][1].equals(id_pw[1]))
                {
                    return "login";
                }
                
                return "wrong pw";
            }
        }
        
        return "fail";
    }
}

 

 

class Solution {
    public String solution(String[] id_pw, String[][] db) {
        String id = id_pw[0];
        
        for(String[] user : db)
        {
            if(id.equals(user[0]))
            {
                if(id_pw[1].equals(user[1])) return "login";
                return "wrong pw";
            }
        }
        
        return "fail";
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[] solution(string[] keyinput, int[] board) {
        int[] answer = new int[2];
        int updown = 0;
        int rightleft = 0;
        
        for(int i = 0;i<keyinput.Length;i++)
        {
            if(keyinput[i] == "left" && rightleft > -1*board[0]/2)
            {
                answer[0] -= 1;
                rightleft--;
            }
            else if(keyinput[i] == "right" && rightleft < board[0]/2)
            {
                answer[0] += 1;
                rightleft++;
            }
            else if(keyinput[i] == "up" && updown < board[1]/2)
            {
                answer[1] += 1;
                updown++;
            }
            else if(keyinput[i] == "down" && updown > -1 * board[1]/2)
            {
                answer[1] -= 1;
                updown--;
            }
        }
        
        return answer;
    }
}

 

 

자바

 

class Solution {
    public int[] solution(String[] keyinput, int[] board) {
        int numRow = board[1];
        int numCol = board[0];
        int r = 0;
        int c = 0;
        for (String key : keyinput) 
        {
            switch (key.charAt(0)) 
            {
                case 'l':
                    c = Math.max(-numCol / 2, c - 1);
                    break;
                case 'r':
                    c = Math.min(numCol / 2, c + 1);
                    break;
                case 'd':
                    r = Math.max(-numRow / 2, r - 1);
                    break;
                case 'u':
                    r = Math.min(numRow / 2, r + 1);
                    break;
            }
            
            System.out.println(r + " " + c);
        }
        
        return new int[]{c, r};
    }
}

 

 

class Solution {
    public int[] solution(String[] keyinput, int[] board) {
        int[] now = {0, 0};
        
        for (int i = 0; i < keyinput.length; i++)
        {
            if(keyinput[i].equals("left")) 
              now[0] -= now[0]>-(board[0]/2)?1:0;
            else if(keyinput[i].equals("right"))
              now[0] += now[0]<(board[0]/2)?1:0;
            else if(keyinput[i].equals("down"))
              now[1] -= now[1]>-(board[1]/2)?1:0;
            else if(keyinput[i].equals("up")) 
              now[1] += now[1]<(board[1]/2)?1:0;
        }
        
        return now;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int M, int N) {
        return M*N-1;
    }
}

 

// 계산해보니까 자르는 숫자가 MN-1이다.

 

자바

 

 

class Solution {
    public int solution(int m, int n) {
        return m * n - 1;
    }
}
728x90

설정

트랙백

댓글