티스토리 뷰

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWRKNev6fqYDFAV8


#include <iostream>

#include <memory.h>

#include <string>

using namespace std;


int result, arr[26];

string s;


int main()

{

int T;


cin >> T; int t = 1;

while (T--)

{

cin >> s; result = 0; memset(arr, 0, sizeof(arr));

for (int i = 0; i < s.size();i++) arr[s.at(i) - 97]++;

for (int i = 0; i < 26;i++)result += ((arr[i] * (arr[i] + 1)) / 2);

cout << "#" << t++ << " " << result << endl;

}

return 0;

}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1208] Flatten  (0) 2018.08.06
[SWEA 1206] View  (0) 2018.08.05
[SWEA 4796] 의석이의 우뚝 선 산  (0) 2018.07.26
[SWEA 4789] 성공적인 공연 기획  (0) 2018.07.26
[SWEA 4747] 사막에서 만난 지니  (0) 2018.07.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함