백준 1977번 완전제곱수 [C언어] Sol1) 배열을 사용하지 않은 풀이 #include #include int main() { int from, to, min; //min = 가장 작은 완전 제곱수를 저장할 변수 int cnt = 0, sum = 0, flag = 0; //flag로 처음 들어오는 완전 제곱수를 체크한다. scanf("%d", &from); scanf("%d", &to); for(int i = from; i BOJ 2022.08.08
백준 1436번 영화감독 숌 [C언어] Sol1) 문자열과 동적 할당을 이용한 풀이 -> 메모리와 시간 많이 사용. #include #include #include int main() { int n, cnt = 0; scanf("%d", &n); for(long long i = 666;;i++){ int len = 0; //i의 자릿수를 저장할 변수 long long temp = i; while(temp > 0){ //계속 자릿수를 하나씩 깎아나가며 len 카운트. temp /= 10; len++; } char *num = malloc(sizeof(char) * (len + 1)); //NULL까지 고려해 len + 1만큼 메모리 할당 sprintf(num,"%lld", i); //sprintf함수로 정수를 문자열로 저장. if(strstr(.. BOJ 2022.08.07
메모리 관련 함수 32비트에서 포인터가 저장하는 주소값의 크기는 4바이트, 64바이트에서는 8바이트이다. malloc함수로 포인터 변수에 메모리 동적 할당 가능. malloc 함수는 할당하고자 하는 메모리 크기를 매개변수로 받고, 할당에 성공하면 메모리 주소를 리턴하고, 실패하면 NULL을 리턴한다. 동적 할당과 일반 변수 생성시 사용하는 메모리 부분은 다르다. malloc함수는 heap부분의 메모리를 사용하고 변수는 stack부분의 메모리에 생성된다. malloc 함수로 할당한 메모리에 값을 저장할 때는 *ptr = 10;처럼 포인터를 역참조한 뒤 값을 저장한다. #include #include int main(){ int *ptr; ptr = malloc(sizeof(*ptr)); //포인터가 가리키는 자료형의 크기만.. Notes for C 2022.08.07
#2577(java) Solution1) import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { int A = 0, B = 0, C = 0; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); A = Integer.parseInt(br.readLine()); B = Integer.parseInt(br.readLine()); C = Integer.parseInt(br.readLine()); int result = A * B * C; ArrayList nums = new ArrayList(); //r.. BOJ 2022.07.02
String, StringBuffer and StringBuilder String . - String is immutable. - It seems mutable in certain cases, but it is a misconception. String hi = "Hi" hi += "Hello" //it seems that we just changed the object itself from "Hi" to "HiHello" //but what really happened is that we created a new String value "HiHello" and //changed the reference of the object hi from "Hi" to "HiHello" StringBuffer - StringBuffer is a data type that is used.. Notes for Java 2022.07.01
Methods of String String.format - returns a formatted String value. ex) String.format("The answer is %d", 3) returns "The answer is 3" - can be used with System.out.println ex) System.out.println(String.formate("The answer is %d", 3)) String.split("delimiter") - splits the String value using delimiter and returns a String type array. String hi = "Hi Hello"; String[] prac = hi.split("H"); //prac = ["", "i ", "ello.. Notes for Java 2022.07.01