본문 바로가기
Computer Science

콩순이의 팰린드롬

by OKOK 2019. 2. 12.

1. 어떤 해당 알고리즘이 필요한 것이 아니라,

2. 해당 알고리즘은 없고

3. 그 때 필요한 형식을 찾아서 풀이하는 것이 최고임 


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
32
33
#include <stdio.h>
#define LSUM(n) n*(n+1)/2
#define LEN 10
 
int count[26];
int main(void)
{
    freopen("input.txt""r", stdin);
    int T, test_case;
    scanf("%d"&T);
 
    for (test_case = 1; test_case <= T; test_case++)
    {
        char W[LEN + 1], *p;
        int i, sum;
 
        for (int i = 0; i < 26; i++) count[i] = 0// 초기화
 
        scanf("%s", W);
        p = W;
 
        while (*!= '\0')
            count[*(p++- 'a']++;
 
        sum = 0;
        for (i = 0; i < 26; i++)
            sum += LSUM(count[i]);
 
        printf("%d\n", sum);
    }
    return 0;
}
 
cs

 


'Computer Science' 카테고리의 다른 글

콩순이의 가장 싼 팰린드롬  (0) 2019.02.12
테네스의 특별한 소수  (0) 2019.02.12
다솔이의 다이아몬드 장식  (0) 2019.02.12
호엽이의 우뚝 선 산  (0) 2019.02.12
신혜의 직선 긋기 게임  (0) 2019.02.11

댓글