Advertisement
Guest User

cf960A

a guest
Apr 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. /*
  2. Solved!
  3. Date: 20-04-18
  4. Time: 09:59:22
  5. */
  6.  
  7. #include <iostream>
  8. #include <bits/stdc++.h>
  9. #include <algorithm>
  10.  
  11. using namespace std;
  12.  
  13. int global;
  14.  
  15. int order(int len, char word[]){
  16. int i;
  17.  
  18. for(i = 0; i < len; i++){
  19. if(word[i] == 'b' || word[i] == 'c'){
  20. return -1;
  21. } else if (word[i] == 'a'){
  22. global = i;
  23. return 1;
  24. }
  25. }
  26. }
  27.  
  28. int order2(int len, char word[]){
  29. int i;
  30.  
  31. for(i = global + 1; i < len; i++){
  32. if(word[i] == 'c'){
  33. return -1;
  34. } else if (word[i] == 'b'){
  35. return 1;
  36. }
  37. }
  38. }
  39.  
  40. int main(){
  41. freopen("input.txt", "r", stdin);
  42. freopen("output.txt", "w", stdout);
  43.  
  44. char word[10000];
  45.  
  46. scanf("%s", word);
  47.  
  48. int len = strlen(word);
  49.  
  50. int a = 0, b = 0, c = 0;
  51.  
  52. if(order(len, word) == 1){
  53. if(order2(len, word) == 1){
  54. for(int i = 0; i < len; i++){
  55. if(word[i] == 'a'){
  56. a++;
  57. } else if (word[i] == 'b'){
  58. b++;
  59. } else {
  60. c++;
  61. }
  62. }
  63. } else {
  64. printf("NO\n");
  65. return 0;
  66. }
  67.  
  68. } else {
  69. printf("NO\n");
  70. return 0;
  71. }
  72.  
  73. int flag_a = 0, flag_b = 0, flag_c = 0;
  74. if(c == a || c == b){
  75. for(int i = 0; i < len; i++){
  76. if(word[i] == 'a'){
  77. flag_a = 1;
  78. } else if (word[i] == 'b'){
  79. flag_b = 1;
  80. } else {
  81. flag_c = 1;;
  82. }
  83.  
  84. if((flag_a == 1 && flag_b == 1 && word[i] == 'a') || (flag_a == 1 && flag_b == 1 && flag_c == 1 && (word[i] == 'a' || word[i] == 'b'))){
  85. printf("NO\n");
  86. return 0;
  87. }
  88. }
  89.  
  90. printf("YES\n");
  91. } else {
  92. printf("NO\n");
  93. }
  94.  
  95.  
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement