codechef BUY1GET1 - "buy1-get1" solution: http://ideone.com/59HWlx
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
 int t, n, b[205], cnt;
 char s[205];
 scanf("%d", &t);
 while(t--) {
  scanf("%s", s);
  n=strlen(s); cnt=0;
  for(int i=0; i<n; i++) b[i]=1;
  for(int i=0; i<n-1; i++) {
   if(b[i]==0) continue;
   for(int j=i+1; j<n; j++) {
    if(s[i]==s[j]) { b[j]=0; break; }
   }
  }
  for(int i=0; i<n; i++) cnt += b[i];
  printf("%d\n", cnt);
 }
 return 0;
}
No comments:
Post a Comment