SOLUTION INFO
C++ · main.cpp
- 작성자
- tony9402
- 공동 작성자
- 없음
#include<bits/stdc++.h>
using namespace std;
const int cnt[] = {3,2,1,2,3,3,3,3,1,1,3,1,3,3,1,2,2,2,1,2,1,1,2,2,2,1};
int arr[1000001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string S; cin >> S;
for(int i = 0; i < S.size(); ++i) {
arr[i] = cnt[S[i] - 'A'];
}
int N = S.size();
while(N != 1) {
for(int i = 1; i < N; ++i) {
arr[i / 2] += arr[i];
arr[i / 2] %= 10;
arr[i] = 0;
}
N = (N + 1) / 2;
}
if(arr[0] % 2 == 0) {
cout << "You're the winner?";
}
else {
cout << "I'm a winner!";
}
return 0;
}
SOLUTION DESCRIPTION
풀이 설명
주어진 조건대로 잘 구현하면 되는 문제이다.
위에서 사용한 기법은 추가 메모리 없이 하나의 배열로 계산하는 방법이다.
SOLUTION INFO
Java · Main.java
- 작성자
- lms0806
- 공동 작성자
- 없음
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int[] num = {3, 2, 1, 2, 3, 3, 3, 3, 1, 1, 3, 1, 3, 3, 1, 2, 2, 2, 1, 2, 1, 1, 2, 2, 2, 1};
public static void main(String[] args) throws IOException{
FastReader rd = new FastReader();
int n = 0;
for(char ch : rd.nextLine().toCharArray()) {
n += num[ch - 'A'];
if(n > 9) {
n %= 10;
}
}
System.out.print(n % 2 == 1 ? "I'm a winner!" : "You're the winner?");
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.
SOLUTION INFO
Python · main.py
- 작성자
- gusdn3477
- 공동 작성자
- 없음
import sys
def input():
return sys.stdin.readline().rstrip()
DB = [3, 2, 1, 2, 3, 3, 3, 3, 1, 1, 3, 1, 3, 3, 1, 2, 2, 2, 1, 2, 1, 1, 2, 2, 2, 1]
dic = {}
for idx, data in enumerate(DB):
dic[chr(idx+65)] = DB[idx] # 'A' : 65
total = 0
a = input()
for i in a:
total += dic[i]
total = total % 10
if total % 2 == 1:
print("I'm a winner!")
else:
print("You're the winner?")
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.