fork(1) download
  1. #include <cstring>
  2. #include <iostream>
  3. #include <cstdio>
  4. using namespace std;
  5. int main (void)
  6. {
  7. int t, i, len, j, developer, tester;
  8. char str[100001];
  9. scanf ("%d", &t);
  10. for (t; t > 0; --t)
  11. {
  12. scanf ("%s", str);
  13. len = strlen(str);
  14. tester = 0;
  15. developer = 0;
  16. for (i = 0; i < len; ++i)
  17. {
  18. if (str[i] == 'D')
  19. {
  20. ++developer;
  21. }
  22. }
  23. j = 0;
  24. for (i = 0; i < len; ++i)
  25. {
  26. if (str[i] == 'D')
  27. {
  28. for (j ; j < i; ++j)
  29. {
  30. if (str[j] == 'T')
  31. {
  32. str[j] = '0';
  33. ++tester;
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. if (developer == tester)
  40. {
  41. printf ("YES\n");
  42. }
  43. else
  44. {
  45. printf ("NO\n");
  46. }
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0s 3320KB
stdin
5
TTDD
DDDDDD
TTDTDD
DTTD
TTDDTTDD
stdout
YES
NO
YES
NO
YES