Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. 1. Get the longest consecutive occurence of a character in a given string and the position of the start of the sequence.
  2. def sequence(str, pos, len)
  3. Change the behavior of the code if the programming language you use does not accept pass by reference.
  4.  
  5. public class JeromeSevilla {
  6.  
  7. public static void main(String[] args) {
  8. JeromeSevilla js = new JeromeSevilla();
  9. PosLen posLen = seq("asdfffffsdfsdttmmmmmdf");
  10. System.out.println("len = " + posLen.getLen() + " pos " + posLen.getPos())
  11. }
  12. public PosLen seq(String str) {
  13. int pos = 0;
  14. int len = 0;
  15. int lastPos = 0;
  16. int longest = 0;
  17.  
  18. for (int i = 0; i < str.length() - 1; i++ ) {
  19. if (str.charAt(i) == str.charAt(i + 1)) {
  20. if (len == 0)
  21. pos = i;
  22.  
  23. len ++;
  24. } else {
  25. if (len > longest) {
  26. longest = len;
  27. lastPos = pos;
  28. }
  29. pos = 0;
  30. len = 0;
  31. }
  32. }
  33.  
  34. return new PosLen(lastPos, longest);
  35. }
  36. }
  37.  
  38. public class PosLen {
  39. private int pos;
  40. private int len;
  41.  
  42. public PosLen(int pos, int len) {
  43. this.pos = pos;
  44. this.len = len;
  45. }
  46.  
  47. // getters
  48. }
  49.  
  50. 2. two integers a and b, ascending blahblah, if odd +, if even *, if a is < b return a ifa == b return a + b
  51. ex: func(3, 6)
  52. (((3 + 4) * 5) + 6))
  53. func(3, 3)
  54. 3
  55. func(4, 3)
  56. 4
  57.  
  58. public int test(int a, int b) {
  59. return (a < b) ? a : (a == b) ? a + b : ;
  60.  
  61. return (a % 2 == 0) ? a + func( //hangga kumu keni, megisan oras,
  62. // mimisip kung mag recursion sana para pogi points
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement