fork download
  1. #include<stdio.h>
  2. char S[55];
  3. int cnt[256], ans = 0;
  4. int main() {
  5. scanf("%s", S);
  6. for (int i = 0; S[i]; i++) {
  7. if (cnt[S[i]]) {
  8. for (int j = 'A'; j <= 'Z'; j++) ans+=cnt[j]>cnt[S[i]];
  9. cnt[S[i]] = 0;
  10. }
  11. else cnt[S[i]] = i;
  12. }
  13. printf("%d", ans);
  14. return 0;
  15. }
Success #stdin #stdout 0s 4252KB
stdin
ABCCABDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ
stdout
1