Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. import java.util.*;
  2. public class DN05 {
  3.  
  4. public static String pip_next(String s){
  5. StringBuffer outn=new StringBuffer("");
  6. int dod=0;
  7. int neki=s.length();
  8. char n=s.charAt(0);
  9.  
  10. for(int i=0; i<neki;i++){
  11. if(n==s.charAt(i)){
  12. dod++;
  13. }
  14. else if(n != s.charAt(i)){
  15. outn=outn.append(dod);
  16. outn=outn.append(s.charAt(i - 1));
  17. n=s.charAt(i);
  18. dod=1;
  19. }
  20. if(i == neki - 1){
  21. outn=outn.append(dod);
  22. outn=outn.append(s.charAt(i));
  23. }
  24. }
  25.  
  26. return outn.toString();
  27. }
  28.  
  29. public static String pip(String beseda,int kokrat)
  30. {
  31. System.out.println(beseda);
  32. for(int iStevec=1;iStevec<kokrat;iStevec++)
  33. {
  34. beseda=pip_next(beseda);
  35. System.out.println(beseda);
  36. }
  37. return beseda;
  38. }
  39. public static int stop1(int n){
  40. if(n==1){
  41. return 1;
  42. }
  43. if(n%2==0)
  44. {
  45. return stop1(n/2)+1;
  46. }
  47. else
  48. return stop1(3*n+1)+1;
  49. }
  50. public static int stop1_2n(int n){
  51. if(n==1){
  52. return 1;
  53. }
  54. if(n%2==0)
  55. {
  56. return stop1(n/2)+1;
  57. }
  58. else
  59. return stop1(3*n+1)+1;
  60. }
  61. public static void vsota(int n,int m, int max, int seed){
  62. Random neki=new Random(seed);
  63. int min=-max;
  64. float[][] izpis=new float [n][m];
  65. float[] pol=new float[m];
  66. for(int i=0;i<n;i++){
  67. for(int j=0;j<m;j++){
  68. izpis [i][j]=min+neki.nextFloat()*2*max;
  69. }
  70. }
  71. for(int i=0;i<n;i++){
  72. for(int j=0;j<m;j++){
  73. System.out.printf("%6.2f", izpis [i][j]);
  74. }
  75. System.out.println();
  76. }
  77. System.out.printf("S(x) = ");
  78. for(int i=0;i<m;i++){
  79. for(int j=0;j<n;j++){
  80. pol[i]=pol[i]+izpis[j][i];
  81. }
  82. if(i==0 &&pol[0]>0){
  83. System.out.printf("%2.1fx^%d", pol[i], m-i-1);
  84. /*
  85. if(m-i-1==0){
  86. System.out.printf("%+2.1f", pol[i]);
  87. break;
  88. }
  89. if(m-i-1==1){
  90. System.out.printf("%+2.1fx", pol[i]);
  91. }
  92. else{
  93. System.out.printf("%+2.1fx^%d", pol[i], m-i-1);
  94. }*/
  95. }
  96. else{
  97. if(m-i-1==0){
  98. System.out.printf("%+2.1f", pol[i]);
  99. break;
  100. }
  101. if(m-i-1==1){
  102. System.out.printf("%+2.1fx", pol[i]);
  103. }
  104. else{
  105. System.out.printf("%+2.1fx^%d", pol[i], m-i-1);
  106. }
  107. }
  108. }
  109. }
  110. public static void main(String[] args){
  111. if(args[0].equals("1a")){
  112. String nova=pip_next(args[1]);
  113. System.out.printf(nova);
  114. }
  115. else if(args[0].equals("1b")){
  116. pip(args[1],Integer.parseInt(args[2]));
  117. }
  118. else if(args[0].equals("2a")){
  119. System.out.print(stop1(Integer.parseInt(args[1])));
  120. }
  121. else if(args[0].equals("2b")){
  122. System.out.print(stop1_2n(Integer.parseInt(args[1])));
  123. }
  124. if(args[0].equals("3"))
  125. {
  126. vsota(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]));
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement