Advertisement
Kaidul

UVa 12708

Dec 14th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define Max 1005
  4.  
  5. using namespace std;
  6.  
  7. int main(void) {
  8.     freopen("input.txt", "r", stdin);
  9.     int tcase, caseNo = 0;;
  10.     char input[Max];
  11.     scanf("%d", &tcase);
  12.     getc(stdin);
  13.     while (tcase--) {
  14.         gets(input);
  15.         int total = 0;
  16.         int length = strlen(input);
  17.         //total += length;
  18.         for(int i = 0; i < length; ++i) {
  19.             map <char, int> parity;
  20.             int oddParity = 0, previous, j;
  21.             for(int k = 0; k < length - i; ++k) {
  22.                 j = i + k;
  23.                 previous = parity[input[j]];
  24.                 ++parity[input[j]];
  25.                 if(parity[input[j]] == 1)
  26.                     ++oddParity;
  27.                 else if(previous & 1)
  28.                     --oddParity;
  29.                 else
  30.                     ++oddParity;
  31. //                map <char, bool> taken;
  32. //                for(int indx = i; indx <= j; ++indx) {
  33. //                    if(parity[input[indx]] & 1 and !taken[input[indx]]) {
  34. //                        ++oddParity;
  35. //                        taken[input[indx]] = true;
  36. //                    }
  37. //                }
  38.                 if(oddParity < 2)
  39.                     total++;
  40.             }
  41.         }
  42.         /*
  43.         for(int k = 1; k < length; ++k) {
  44.             for(int i = 0; i < length - k; ++i) {
  45.                 int j = i + k;
  46.                 map <char, int> parity;
  47.                 for(int indx = i; indx <= j; ++indx) {
  48.                     ++parity[input[indx]];
  49.                 }
  50.                 int oddParity = 0;
  51.                 map <char, bool> taken;
  52.                 for(int indx = i; indx <= j; ++indx) {
  53.                     if(parity[input[indx]] & 1 and !taken[input[indx]]) {
  54.                         ++oddParity;
  55.                         taken[input[indx]] = true;
  56.                     }
  57.                 }
  58.                 if(oddParity < 2)
  59.                     total++;
  60.             }
  61.         }
  62.         */
  63.         printf("Case %d: %d\n", ++caseNo, total);
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement