본문 바로가기

프로그래머스 문제풀이15

프로그래머스 Level 1 : 두 정수 사이의 합 public class Solution { public long solution(int a, int b) { long answer = 0; if (a < b) { for (int i = a; i =b; i--) { answer += i; } } return answer; } } a와 b의 범위는 -10,000,000에서 +10,000,000까지이다. 1. a의 입력 값이 b의 입력 값보다 작을 때와 a의 입력 값이 b의 입력 값보다 클 때를 지정해줍니다. 2. 그리고 각각 내부에 a부터 b까지 반복하는 함수와 해당 값을 answer에 저장합니다. 3. a가 b보다 작을 때는 a부터 b까지 증가하는 반복문을 4. a가 b보다 작을 때는 a부터 b까지 감소하는 반복문을 선언해주어 문제를 해결합니다. 2020. 6. 25.
프로그래머스 LEVEL 1 : 직사각형 별찍기 using System; public class Example { public static void Main() { String[] s; Console.Clear(); s = Console.ReadLine().Split(' '); int a = Int32.Parse(s[0]); int b = Int32.Parse(s[1]); for(int i = 0; i 2020. 6. 25.
프로그래머스 LEVEL1 : 약수의 합 public class Solution { public int solution(int n) { int answer = 0; for(int i = 1; i 2020. 6. 25.
프로그래머스 LEVEL 1 : 문자열을 정수로 바꾸기 using System; public class Solution { public int solution(string s) { int answer = Convert.ToInt32(s); return answer; } } 문자열을 정수형으로 변환하는 함수인 Convert.ToInt32()를 사용하여 해결 Convert.ToInt32() 을 사용할 때는 상단에 using System을 선언 해주어야 한다. 2020. 6. 25.
프로그래머스 Level 1 : 수박수박수박수박수박수? public class Solution { public string solution(int n) { string answer = ""; for(int i=0; i 2020. 6. 25.
반응형