[ccNOV14] Distinct Characters Subsequence

描述 Description

You have initially a string of N characters, denoted by A1,A2…AN. You have to print the size of the largest subsequence of string A such that all the characters in that subsequence are distinct ie. no two characters in that subsequence should be same.

A subsequence of string A is a sequence that can be derived from A by deleting some elements and without changing the order of the remaining elements.

输入格式 InputFormat

First line contains T, number of testcases. Each testcase consists of a single string in one line. Each character of the string will be a small alphabet(ie. ‘a’ to ‘z’).

输出格式 OutputFormat

For each testcase, print the required answer in one line.

样例输入 SampleInput

2
abc
aba

样例输出 SampleOutput

3
2


CodeChef DISCHAR


找有多少个不同的字符即可。

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int i,j,t,n,m,l,r,k,z,y,x;
char a[100005];
bool s[150];
int T,ans;
int main()
{
    scanf("%d",&T);
    while (T--)
    {
        memset(s,false,sizeof(s));
        ans=0;
        scanf("%s",a);
        n=strlen(a);
        for (i=0;i<n;i++) if (!s[(int)a[i]])
        {
            s[(int)a[i]]=true;
            ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}