[1934번 c#] 최소공배수
·
c#/백준알고리즘
두 수를 곱한 값 -> 최대공약수 x 최소공배수 재귀를 이용하여 최대공약수와 최소공배수를 찾아준다. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Project2 { class Class1 { static void Main(string[] args) { StreamWriter writer = new StreamWriter(Console.OpenStandardOutput()); StreamReader reader = new StreamReader(Console.OpenStandardInput()); ..
[백준 2798번 c#] 블랙잭
·
c#/백준알고리즘
브루트포스 알고리즘 이 쓰인 문제이다. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Project2 { class Class1 { static void Main(string[] args) { //N,M 값 입력 string[] N_M = Console.ReadLine().Split(); int N = int.Parse(N_M[0]); int M = int.Parse(N_M[1]); //카드에 쓰여진 수 입력 string[] nums = Console.ReadLine().Split(); int[] numsInt = new int..
[백준 11653번 c#] 소인수분해 구하기
·
c#/백준알고리즘
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class Program { public static void Main() { //정수 N 소인수분해하기 int N = int.Parse(Console.ReadLine()); for(int i=2; i
[백준 10757번 c#] 큰 수 A+B
·
c#/백준알고리즘
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class Program { public static void Main() { String[] str = Console.ReadLine().Split(' '); BigInteger a = BigInteger.Parse(str[0]); BigInteger b = BigInteger.Parse(str[1]); Console.WriteLine(a + b); } } c# 에서는 using System.Numerics; 에서 BigInteger을 통해 큰 수를 사..
[백준15552번 c#] 빠른 A+B
·
c#/백준알고리즘
'빠른' 이 핵심 포인트이다 using System; using System.Text; public class Program { public static void Main() { int T = int.Parse(Console.ReadLine()); int[] a = new int[T]; int[] b = new int[T]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < T; i++) { String[] strings = Console.ReadLine().Split(' '); a[i] = int.Parse(strings[0]); b[i] = int.Parse(strings[1]); sb.Append(a[i] + b[i]+"\n"); } Cons..
[백준/자바]3052번: 나눗셈
·
자바/백준 알고리즘(자바)
-Set은 중복된 값을 가지지 않는 Collection -배열을 Set 타입(HashSet)으로 변환하면, 중복을 제거할 수 있음 -배열의 순서를 보장하면서, 중복을 제거해야 할 때는 LinkedHashSet을 사용 import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; import javax.print.DocFlavor.STRING; public class Main { public static void main(String args[]) throws NumberFormatException, IOException{ Scanner sca..
[백준/자바]2577번: 숫자의 개수/자바/java/
·
자바/백준 알고리즘(자바)
-BufferedReader 사용하여 int로 값 저장 -String.valueOf 로 int를 String으로 변경 -str.charAt(i)을 통해 string을 각각의 char로 바꾸고, 아스키코드 이용하여 arr에 저장해줌 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String args[]) throws NumberFormatException, IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ..
[백준/자바]2562번: 최대값
·
자바/백준 알고리즘(자바)
for문을 for(int value: a) 로 사용 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner in=new Scanner(System.in); int a[] = new int[9]; int max=0, index=0, count=0; for(int i=0; imax) { max = value; index = count; } } System.out.println(max); System.out.println(index); } }
[백준/자바]10818번: 최소, 최대/ 자바/java
·
자바/백준 알고리즘(자바)
scanner로 값을 배열로 받고, Arrays.sort() 메소드를 이용하여 정렬 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner in=new Scanner(System.in); int N=in.nextInt(); int a[] = new int[N]; int b=0,c=0; for(int i=0; i
[백준/자바] 10951번: A+B - 4
·
자바/백준 알고리즘(자바)
* EOF를 이용하여 Scanner 처리하기 import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner in=new Scanner(System.in); while(in.hasNextInt()){ int a=in.nextInt(); int b=in.nextInt(); System.out.println(a+b); } in.close(); } }