CodeTree 쌀 기부

코드트리에서 5월 7일 하루동안 하는 이벤트로, 푼 문제 수 만큼 쌀을 기부해주는 이벤트이다.

2문제를 풀어서 2kg을 기부했다. 문제만 풀어도 쌀이 기부되는 거라 더 열심히 풀었던 것 같다.

 

 

solved.ac 현황

스트릭은 29일, 랭킹은 아직 silver 2이다.

열심히 해서 32일을 꼭 채우고 싶다!!

728x90

'Diary' 카테고리의 다른 글

Solved.ac 새싹 5단계 달성🌱  (0) 2022.05.11
Solved.ac 새싹 4단계 달성😊  (0) 2022.04.25
퍼스널 컬러 받은 날  (0) 2022.02.22
1월 21일 일기  (0) 2022.01.22
1월 20일 일기  (0) 2022.01.20

오랜 구글링 끝에 이 방법으로 위 오류를 해결할 수 있었다. 다른 해결 방법도 많이 시도해봤지만, 해결되는 것은 없었다.

wsl에 아래 명령어를 실행하고, npm install 후 npm start를 해서 다시 앱을 실행했다. 

 

만약 명령어를 실행했는데도 오류는 안 나지만 폰트가 적용되지 않는다면, style에 fontWeight을 정의했는지 봐야 한다. fontWeight을 지정하면 폰트가 적용되지 않는다. 제거해야 한다.

 

window

rm -rf $TMPDIR/react-* && rm -rf node_modules/ && rm -f package-lock.json && rm -f yarn.lock && npm cache verify && npm install && expo r -c

 

mac

watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && rm -f package-lock.json && rm -f yarn.lock && npm cache verify && npm install && expo r -c

 

 

※ 출처 및 참고

https://intrepidgeeks.com/tutorial/reactnative-error-fontfamily-error

 

 

728x90

개발을 얼마 하지도 않았는데 갑자기 react native expo Attempt to invoke virtual method 'boolean abi .facebook.. 라는 에러가 떴다.

 

구글링을 통해 찾아보니, 이 오류는 안드로이드 폰에서만 발생하는 문제이고, Expo 앱의 2.24.1 버전에서 발생한다는 것을 알았다. 따라서 Expo 앱을 2.23.2로 다운 그레이드 하는 것이 필요했다.

 

https://apkcombo.com/ko/expo/host.exp.exponent/ 이 사이트에 들어가서  Expo 앱의 2.23.2 버전 apk를 다운 받았다.

그리고 핸드폰에 있는 Expo를 삭제한 뒤, 설정 > 생체 인식 및 보안 > 출처를 알 수 없는 앱 설치 에 들어가 허용을 해주었다. 그 후, 다운 받은 apk를 실행했다.

 

왜 새로운 버전의 Expo에서 안드로이드만 오류가 나는지 모르겠다.

 


Expo 앱이 알아서 업데이트가 되는 바람에 다른 방법을 찾아야했다.

expo 버전을 45.0.1로 업데이트해서 문제를 해결했다.

expo upgrade
728x90

문제

Backward numbers are numbers written in ordinary Arabic numerals but the order of the digits is reversed. The first digit becomes the last, and vice versa. For example, the number 1245 becomes 5421. Note that all leading zeroes are omitted. This means that if the number ends with a zero, the zero is lost by the reversal; e.g., 1200 gives 21. Also note that the reversed numbers never have any trailing zeroes.

We need to calculate with backward numbers and your task is to write a program that can add two backward numbers and output their sum as a backward number. Of course, the result is not unique (e.g., 21 could be 12, 120, or 1200 before the reversal). Thus, we assume that no zeroes were lost in the reversal (e.g., we assume that the original number was 12).

 

입력

The input consists of N cases. The first input line contains only the integer N, and we assume that N > 0. The follow the cases. Each case consists of exactly one line with two non-negative integers separated by a space. These are the reversed numbers you are to add.

We assume that all numbers are in the range 0 ≤ n < 109.

 

출력

For each case, print exactly one line containing only one integer—the backward sum of the two backward numbers. Omit any leading zeroes in the output.


코드

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb;

        int N = Integer.parseInt(br.readLine());

        for(int i = 0; i < N; i++){
            String[] arr = br.readLine().split(" ");
            for(int j = 0; j <2; j++){
                sb = new StringBuffer(arr[j]);
                arr[j] = sb.reverse().toString();
            }
            int sum = Integer.parseInt(arr[0]) + Integer.parseInt(arr[1]);
            String sumSt = Integer.toString(sum);
            sb = new StringBuffer(sumSt);
            System.out.println(Integer.parseInt(sb.reverse().toString()));
        }

    }
}

 

풀이

이 문제는 두 수를 입력받고 각각 reverse 한 뒤 더해서 다시 reverse 한 값을 출력하는 것이다.

예를 들어 예제 입력 1에 있는 24와 1의 경우, 24를 거꾸로 바꿔서 42로, 1을 거꾸로 바꿔서 1로 해놓고 더하면 43이 된다. 그리고 다시 거꾸로 바꾸면 34가 된다. 즉 답은 34가 된다.

또 다른 예시인 794의 경우, 305를 바꾼 503과 794를 바꾼 497을 더해준다. 그럼 1000이 나오고, 1000을 거꾸로 바꾸면 0001이 된다. 이때 숫자의 경우 앞에 있는 0은 생략해주기 때문에 1이 나오게 된다.

 

숫자를 int로 입력받아서 거꾸로 돌리는 게 복잡할 것 같아 일단 입력을 다 String으로 받고, StringBuffer에 있는 함수인 reverse를 이용해 입력받은 숫자를 거꾸로 돌려주었다. 거꾸로 돌린 숫자들을 Integer.parseInt()로 숫자로 바꾼 후 더해주었고, 그걸 다시 String으로 변환해 reverse함수로 거꾸로 돌려주었다.

앞에 0이 있는 경우를 대비해 출력할 때 int로 형을 변환해서 출력해주었다.

728x90

'Algorithm > 백준' 카테고리의 다른 글

[백준][Java] 10816. 숫자 카드 2  (0) 2024.02.05
[백준][Java] 1541. 잃어버린 괄호  (0) 2024.01.31
[백준][Python] 7360. Undercut  (0) 2022.04.30
[백준][Java] 1912. 연속합  (0) 2022.04.28
[백준][Python] 19604. Art  (0) 2022.04.25

문제

Undercut is a card game where two players each have five cards numbered one through five. At each round, each player selects a card, then simultaneously reveals it. If the cards are of equal value, there is no score. Otherwise, there are two cases: the two cards are exactly one point apart (this is called an undercut), or the cards are more than one point apart. In the latter case, the person revealing the larger of the cards gets the number of points on the larger card. In the case of an undercut the player with the lower card gets the sum of the two cards. The exception to this is when the cards are 1 and 2, in which case the player with the lower card gets 6 points (instead of only 3 points). After each round, the cards are returned to the hands and they play another round.

For example, if there are 5 rounds and player A plays (in this order) 5, 3, 1, 3, 5 and player B plays 3, 3, 3, 3, 4, then the scoring for each round would be: A gets 5 points, no points, B gets 3 points, no points, B gets 9 points. The totals would be A: 5, B: 12.

In this problem you will be given card plays for both players and must determine the final scores.

 

입력

There will be multiple input instances. Each instance will be one game. The first line of input for a game will be an integer n <= 20. (A value of n = 0 terminates input.) The next two lines will each contain n integers between 1 and 5 inclusive indicating the cards played on each of n rounds. The first line are player A's card plays and the second line are player B's card plays.

 

출력

Each input instance should generate one line of output of the form:

A has a points. B has b points.

where the value of a and b are for you to determine. A blank line should separate output lines.


코드

import sys

if __name__ == '__main__':

    while True:
        plays = int(sys.stdin.readline().rstrip())
        
        if plays==0:
            break

        A_point = 0
        B_point = 0

        A = list(map(int, sys.stdin.readline().rstrip().split(" ")))
        B = list(map(int, sys.stdin.readline().rstrip().split(" ")))

        for i in range(plays):
            # 한 개 차이면 적은 수를 가진 애가 이김
            # 자신의 카드 넘버와 상대의 카드 넘버 만큼
            if abs(A[i]-B[i]) == 1:
                if A[i] > B[i]:
                    if A[i] == 2:
                        B_point += 6
                    else:
                        B_point += A[i] + B[i]
                else:   # B[i] > A[i]
                    if B[i] == 2:
                        A_point += 6
                    else:
                        A_point += A[i] + B[i]
            elif A[i] < B[i]:
                B_point += B[i]
            elif A[i] > B[i]:
                A_point += A[i]

        print("A has {} points. B has {} points.\n".format(A_point, B_point))

 

풀이

문제를 먼저 해석해보자면, A와 B가 카드게임을 하는데 이때 이기는 조건이 여러 가지이다.

① 두 카드의 숫자 차이가 1보다 클 경우, 숫자가 큰 카드를 가진 사람이 이긴다. 이때, 얻는 점수는 자신의 카드 숫자만큼이다.(큰 카드)

② 두 카드의 숫자 차이가 1일 경우, 숫자가 작은 카드를 가진 사람이 이긴다. 이때, 얻는 점수는 자신의 카드와 상대방의 카드 숫자를 더한 값이다.

③ ②번의 예외로, 두 카드가 1과 2일 경우, 무조건 낮은 카드를 가진 사람이 6점을 얻는다.

④ 두 카드의 숫자가 같을 경우, 무승부로 아무도 점수를 얻지 않는다.

 

위 조건에 맞춰 풀면 된다. 입력을 0이 나올 때까지 받기 때문에 무한 반복을 하고 0이 나오면 break 할 수 있도록 코드를 작성했다. 첫 번째 if 문에서는 A와 B의 카드 차가 1인지 확인했다. 이때 어느 수가 더 큰지 모르기 때문에 abs() 함수를 이용해 절댓값을 씌워서 1인지 확인했다. 그 후, 두 개의 카드가 각각 1과 2라면 6점을 더해주었다. 이때 이미 if 문에서 카드의 차이가 1인지를 확인했기 때문에 A가 B보다 큰 경우, A가 2인지만 확인해주면 B는 자동으로 1이 되므로 A만 조건식에 써주었다. 두 개의 카드가 1과 2가 아니라면 조건 ②에 따라서 두 카드의 합을 점수에 더해주었다.

두 번째와 세 번째 if문의 경우는 조건 ①에 따른 식으로 큰 카드의 수를 점수에 더해주었다.

728x90

'Algorithm > 백준' 카테고리의 다른 글

[백준][Java] 1541. 잃어버린 괄호  (0) 2024.01.31
[백준][Java] 6721. Backward numbers  (0) 2022.04.30
[백준][Java] 1912. 연속합  (0) 2022.04.28
[백준][Python] 19604. Art  (0) 2022.04.25
[백준][Java] 17548. Greetings!  (0) 2022.04.25

+ Recent posts