Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class DN05 {
- public static String pip_next(String s){
- StringBuffer outn=new StringBuffer("");
- int dod=0;
- int neki=s.length();
- char n=s.charAt(0);
- for(int i=0; i<neki;i++){
- if(n==s.charAt(i)){
- dod++;
- }
- else if(n != s.charAt(i)){
- outn=outn.append(dod);
- outn=outn.append(s.charAt(i - 1));
- n=s.charAt(i);
- dod=1;
- }
- if(i == neki - 1){
- outn=outn.append(dod);
- outn=outn.append(s.charAt(i));
- }
- }
- return outn.toString();
- }
- public static String pip(String beseda,int kokrat)
- {
- System.out.println(beseda);
- for(int iStevec=1;iStevec<kokrat;iStevec++)
- {
- beseda=pip_next(beseda);
- System.out.println(beseda);
- }
- return beseda;
- }
- public static int stop1(int n){
- if(n==1){
- return 1;
- }
- if(n%2==0)
- {
- return stop1(n/2)+1;
- }
- else
- return stop1(3*n+1)+1;
- }
- public static int stop1_2n(int n){
- if(n==1){
- return 1;
- }
- if(n%2==0)
- {
- return stop1(n/2)+1;
- }
- else
- return stop1(3*n+1)+1;
- }
- public static void vsota(int n,int m, int max, int seed){
- Random neki=new Random(seed);
- int min=-max;
- float[][] izpis=new float [n][m];
- float[] pol=new float[m];
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- izpis [i][j]=min+neki.nextFloat()*2*max;
- }
- }
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- System.out.printf("%6.2f", izpis [i][j]);
- }
- System.out.println();
- }
- System.out.printf("S(x) = ");
- for(int i=0;i<m;i++){
- for(int j=0;j<n;j++){
- pol[i]=pol[i]+izpis[j][i];
- }
- if(i==0 &&pol[0]>0){
- System.out.printf("%2.1fx^%d", pol[i], m-i-1);
- /*
- if(m-i-1==0){
- System.out.printf("%+2.1f", pol[i]);
- break;
- }
- if(m-i-1==1){
- System.out.printf("%+2.1fx", pol[i]);
- }
- else{
- System.out.printf("%+2.1fx^%d", pol[i], m-i-1);
- }*/
- }
- else{
- if(m-i-1==0){
- System.out.printf("%+2.1f", pol[i]);
- break;
- }
- if(m-i-1==1){
- System.out.printf("%+2.1fx", pol[i]);
- }
- else{
- System.out.printf("%+2.1fx^%d", pol[i], m-i-1);
- }
- }
- }
- }
- public static void main(String[] args){
- if(args[0].equals("1a")){
- String nova=pip_next(args[1]);
- System.out.printf(nova);
- }
- else if(args[0].equals("1b")){
- pip(args[1],Integer.parseInt(args[2]));
- }
- else if(args[0].equals("2a")){
- System.out.print(stop1(Integer.parseInt(args[1])));
- }
- else if(args[0].equals("2b")){
- System.out.print(stop1_2n(Integer.parseInt(args[1])));
- }
- if(args[0].equals("3"))
- {
- vsota(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement