250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 재귀함수
- 백준
- 중복조합
- 자바
- 파티션 크기 조정
- 전화번호속의암호
- 백준2251
- D드라이브생성
- 완탐
- 23288
- 중복순열
- 알고리즘개념
- 볼륨 만들기
- 코테
- 주사위굴리기2
- 삼성역테
- 정보처리기사
- 순열
- java
- 자바 코테
- Bfs와DFS
- 코테준비
- 완전탐색
- 알고리즘
- 에라토스테네스의채
- 백준13458
- BFS
- 정올 1620
- 백준15652
- N과M
Archives
- Today
- Total
뚱땅뚱땅
[알고리즘]백준 1339번 단어 수학 본문
728x90
문제: https://www.acmicpc.net/problem/1339
1339번: 단어 수학
첫째 줄에 단어의 개수 N(1 ≤ N ≤ 10)이 주어진다. 둘째 줄부터 N개의 줄에 단어가 한 줄에 하나씩 주어진다. 단어는 알파벳 대문자로만 이루어져있다. 모든 단어에 포함되어 있는 알파벳은 최대
www.acmicpc.net
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
bool desc(int a, int b) {
return a > b;
}
int main() {
// ios::sync_with_stdio(false);
int alphabet[26] = { 0, };
int n; //단어의 개수
cin >> n;
int answer = 0; //정답
for (int i = 0; i < n; i++) {
char word[8]; //입력받는 문자
cin >> word;
int len = strlen(word);
int pos = (int)pow(10, len - 1);
for (int j = 0; j < len; j++) {
alphabet[word[j] - 'A'] += pos;
pos /= 10;
}
}
// 알파벳 크기 순 정렬
sort(alphabet, alphabet + 26, desc);
int tmp = 9;
for (int i = 0; i < 26; i++) {
if (alphabet[i] == 0)
break;
answer += (tmp * alphabet[i]);
tmp--;
}
cout << answer;
}
728x90
'알고리즘 > 백준' 카테고리의 다른 글
[문제] 백준 4673번 셀프넘버 (0) | 2021.01.19 |
---|---|
[문제] 백준 8958번 OX 퀴즈 (0) | 2021.01.19 |
[문제] 백준 4344번 평균은 넘겠지 (0) | 2021.01.19 |
[문제] 백준 1110번 더하기 사이클 (0) | 2021.01.19 |
[문제] 코드업 1930번 supersum- 메모이제이션으로 풀기 (0) | 2021.01.19 |
Comments