ICPC Balloons CodeForces - 1703B - 模拟,标记

ICPC Balloons CodeForces - 1703B

在比赛中,气球的分布如下:
每当一个团队解决问题时,该团队就会得到一个气球。
第一个解决问题的团队会获得一个额外的气球。
一场比赛有 26 个问题,标记为 A,B,C,...,Z。
给你比赛中已解决问题的顺序,表示为字符串 s,其中 i-th 字符表示问题 si 由某个团队已解决。
没有团队会两次解决同一个问题。确定团队收到的气球总数。请注意,某些问题可能无法由任何团队解决。

Input

输入的第一行包含一个整数 t (1≤t≤100) — 测试用例的数量。
每个测试用例的第一行包含一个整数 n (1≤n≤50) — 字符串的长度。
每个测试用例的第二行包含一个长度为 n 的字符串 s,由大写英文字母组成,表示解决问题的顺序。

Output

对于每个测试用例,输出一个整数 — 团队收到的气球总数。

Output

对于每个测试用例,输出一个整数 — 团队收到的气球总数。

Sample Input

2
3
ABA
1
A

Sample Output

5
2

分析

开个数组标记该题是否解决

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10,INF=0x3f3f3f3f;
int n; char a[N];

int main(){
    // freopen("data.in", "r", stdin);
    int t; scanf("%d", &t);
    while(t--){
        scanf("%d%s", &n, a);
        int ans=0, vis[26]={0};
        for(int i=0; i<n; i++){
            if(!vis[a[i]-'A']) {
                ans += 2, vis[a[i]-'A']=1;
            }else ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}
posted @ 2022-09-22 13:26  HelloHeBin  阅读(245)  评论(0)    收藏  举报