Guest User

Untitled

a guest
Jul 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class PeopleCircle {
  2. public String order(int numMales, int numFemales, int K) {
  3. int totalPersons = numMales + numFemales;
  4. char[] circle = new char[totalPersons];
  5. int i = -1;
  6. while(numFemales > 0) {
  7. int tmpK = K;
  8. while(tmpK > 0) {
  9. if(i != (totalPersons - 1)) {
  10. i ++;
  11. } else {
  12. i = 0;
  13. }
  14. if(circle[i] != 'F') {
  15. tmpK --;
  16. }
  17. }
  18. circle[i] = 'F';
  19. numFemales --;
  20. }
  21. for(int j = 0; j < totalPersons; j ++) {
  22. if(circle[j] != 'F') {
  23. circle[j] = 'M';
  24. }
  25. }
  26. return new String(circle);
  27. }
  28. }
Add Comment
Please, Sign In to add comment