일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 3회차
- 합격
- 유니티3d
- 정처기 필기
- 토이 프로젝트
- 1인 개발
- 유니티 3D
- 자바스크립트 게임
- Unity
- 게임 제작
- 정보처리기사
- 정처기
- 필기
- unity3d
- 1인 게임
- Unity #Unity2D #Portal
- 게임제작
- 유니티
- FPS
- 게임
- Vampire Survivors
- Unity2D
- portal
- 프로그래머스 #최소힙 #우선순위 큐
- Pong
- 1인 게임 제작
- 퐁
- 자바스크립트
- 게임 개발
- 1인 게임 개발
- Today
- Total
Coding Feature.
백준) 16968번: 차량 번호판 1 in C 본문
solution.
For each character, the number of cases is calculated by dividing the cases between the same or different cases compared to the previous character. For example, case 1: …XX and case 2: …XY.
Let’s take “cccc” as an example. Starting from the first character, it is clear that the number of cases is 26, from a to z. However, with the second character and the rest, there is redundancy.
For the second character, redundancy only occurs with one character, so the number of cases would be 26 * (26 - 1), where minus 1 is for the redundant character.
For the third character, one might think to multiply by 24, since we multiplied by 25 for the second character. However, since we only care about redundancy happening right beside one another, we should multiply it again by 25 and not 24. It does not matter that the first and third characters are the same.
So, if we continue this process, the final answer would be 26 * 25 * 25 * 25.
code.
#include <stdio.h>
#include <string.h>
int main(){
char str[4];
int ans = 1;
scanf("%s", str);
// calculate first character of string.
if(str[0] == 'c')
ans *= 26;
else if(str[0] == 'd')
ans *= 10;
// calculate the rest, starting from second char.
for(int i = 1; i<strlen(str); i++){
if(str[i] == 'c'){ // char.
if(str[i-1] == 'c') // and is redundant. ..cc
ans *= 25;
else // not redundant, ..dc
ans *= 26;
}
else if(str[i] == 'd'){ // decimal
if(str[i-1] == 'd') // and is redundant. ..dd
ans *= 9;
else // not redundant, ..cd
ans *= 10;
}
}
printf("%d\n", ans);
return 0;
}
'코딩테스트 > 백준 solved.ac' 카테고리의 다른 글
백준) 16938번: 캠프 준비 in C (0) | 2023.07.23 |
---|---|
백준) 16936번: 나3곱2 in C (0) | 2023.07.09 |
백준) 16924번: 십자가 찾기 in C (0) | 2023.07.07 |
백준) 16922번 : 로마 숫자 만들기 in C (0) | 2023.07.06 |
백준) 16917번: 양념 반 후라이드 반 in C (0) | 2023.07.05 |