• Source
    1. #include "bits/stdc++.h"
    2.  
    3. using namespace std;
    4.  
    5. stack<char>st;
    6.  
    7. string s;
    8.  
    9. int ans[100];
    10.  
    11. int main()
    12. {
    13. int test,tc=0,i,len;
    14.  
    15. scanf("%d",&test);
    16.  
    17. while(test--)
    18. {
    19. cin>>s;
    20.  
    21. len = s.length();
    22.  
    23. st.push(s[0]);
    24.  
    25. for(i=1;i<len;i++)
    26. {
    27. if(st.top()==s[i])
    28. {
    29. st.pop();
    30. }
    31. else
    32. {
    33. ans[s[i]]++;
    34.  
    35. ans[st.top()]++;
    36.  
    37. st.push(s[i]);
    38. }
    39. }
    40.  
    41. printf("Case %d\n",++tc);
    42.  
    43. for(i=65;i<=90;i++)
    44. {
    45. if(ans[i])
    46. {
    47. printf("%c = %d\n",i,ans[i]);
    48. }
    49. }
    50.  
    51. memset(ans,0,sizeof ans);
    52. }
    53.  
    54. return 0;
    55. }