Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package borisov_lr1;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.Scanner;
- /**
- * Created by Alex on 05.10.2015.
- */
- public class Main {
- public static double [][]C; //
- public static double [][]G; //
- public static double [][]L; //
- public static double []X; //
- public static double []U; //
- public static void main(String[] args) throws Exception
- {
- Scanner in = new Scanner(System.in);
- System.out.println("Введите число узлов");
- int uzl = in.nextInt(); //
- System.out.println("Введите число элементов");
- int elements = in.nextInt(); //
- C = new double[uzl][uzl]; //
- G = new double[uzl][uzl]; //
- L = new double[uzl][uzl]; //
- X = new double[uzl]; //
- U = new double[uzl]; //
- try
- {
- for (int i = 0; i < elements; i++) //
- {
- System.out.println("Enter " + (i + 1) + " element");
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "Cp1251"));
- String q = br.readLine();
- analys_elements(q);
- }
- System.out.println("C = ");
- for(int i = 0; i < uzl; i++)
- {
- for(int j = 0; j < uzl; j++)
- {
- System.out.print(C[i][j] + " ");
- }
- System.out.println();
- }
- System.out.println("G = ");
- for(int i = 0; i < uzl; i++)
- {
- for(int j = 0; j < uzl; j++)
- {
- System.out.print(G[i][j] + " ");
- }
- System.out.println();
- }
- System.out.println("L = ");
- for(int i = 0; i < uzl; i++)
- {
- for(int j = 0; j < uzl; j++)
- {
- System.out.print(L[i][j] + " ");
- }
- System.out.println();
- }
- System.out.println("X = ");
- for(int i = 0; i < uzl; i++)
- {
- System.out.println(X[i]);
- }
- System.out.println("U = ");
- for(int i = 0; i < uzl; i++)
- {
- System.out.println(U[i]);
- }
- }
- catch (Exception e)
- {
- System.out.println(e);
- e.printStackTrace();
- }
- }
- public static void analys_elements(String input) throws Exception
- {
- int count_pointers = 0; //
- for (char element : input.toCharArray()){ //
- if (element == ' ')
- {
- count_pointers++;
- }
- }
- int i, j; //
- int position_type = input.indexOf(" "); //
- String type = input.substring(0, position_type); //
- String sub1 = input.substring(position_type + 1, input.length()); //
- int position_value = sub1.indexOf(" "); //
- String str_position = sub1.substring(0, position_value); //
- double value = Double.parseDouble(str_position); //
- String sub2 = sub1.substring(position_value + 1, sub1.length()); //
- if (count_pointers == 2)
- {
- i = Integer.parseInt(sub2); //
- j = i;
- }
- else
- {
- int node1_position = sub2.indexOf(" "); //
- String str_node1_value = sub2.substring(0,node1_position ); //
- i = Integer.parseInt(str_node1_value); //
- //String sub3 = sub2.substring(node1_position + 1, sub2.length());
- int node2_position = sub2.indexOf(" "); //
- String sub3 = sub2.substring(node2_position + 1, sub2.length()); //
- }
- switch (type)
- {
- case "U":
- U[i-1] = value;
- break;
- case "C":
- if (count_pointers == 2 )
- {
- C[i-1][j-1] = value;
- }
- else
- {
- C[i-1][i-1] = value;
- C[j-1][j-1] = value;
- C[i-1][j-1] = -1 * value;
- C[j-1][i-1] = -1 * value;
- }
- break;
- case "Y":
- if (count_pointers == 2 )
- {
- G[i-1][j-1] = value;
- }
- else
- {
- G[i-1][i-1] = value;
- G[j-1][j-1] = value;
- G[i-1][j-1] = -1 * value;
- G[j-1][i-1] = -1 * value;
- }
- break;
- case "Yb":
- if (count_pointers == 2 )
- {
- G[i-1][j-1] = value;
- }
- else
- {
- G[i-1][i-1] = value;
- G[j-1][j-1] = value;
- G[i-1][j-1] = -1 * value;
- G[j-1][i-1] = -1 * value;
- }
- U[i-1] *= value;
- break;
- case "L":
- if (count_pointers == 2 )
- {
- L[i-1][j-1] = value;
- }
- else
- {
- L[i-1][i-1] = 1 / value;
- L[j-1][j-1] = 1 / value;
- L[i-1][j-1] = -1 / value;
- L[j-1][i-1] = -1 / value;
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement