fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s;
  7. cin>>s;
  8. int x=0;
  9. int y=0;
  10. for(int i=0; i<s.length(); i++){
  11. if(s[i]=='G')
  12. y++;
  13. if(s[i]=='D')
  14. y--;
  15. if(s[i]=='P')
  16. x++;
  17. if(s[i]=='L')
  18. x--;
  19. }
  20.  
  21. if(y>0){
  22. while(y--)
  23. cout<<"D";
  24. }
  25. else if(y<0){
  26. while(y++)
  27. cout<<"G";
  28. }
  29. if(x>0){
  30. while(x--)
  31. cout<<"L";
  32. }
  33.  
  34. else if(x<0){
  35. while(x++)
  36. cout<<"P";
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
GGPPPPDPGGL
stdout
DDDLLLL