Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. package borisov_lr1;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5. import java.util.Scanner;
  6.  
  7. /**
  8. * Created by Alex on 05.10.2015.
  9. */
  10. public class Main {
  11.  
  12. public static double [][]C; //
  13. public static double [][]G; //
  14. public static double [][]L; //
  15.  
  16. public static double []X; //
  17. public static double []U; //
  18.  
  19.  
  20. public static void main(String[] args) throws Exception
  21. {
  22. Scanner in = new Scanner(System.in);
  23.  
  24. System.out.println("Введите число узлов");
  25. int uzl = in.nextInt(); //
  26.  
  27. System.out.println("Введите число элементов");
  28. int elements = in.nextInt(); //
  29.  
  30. C = new double[uzl][uzl]; //
  31. G = new double[uzl][uzl]; //
  32. L = new double[uzl][uzl]; //
  33.  
  34. X = new double[uzl]; //
  35. U = new double[uzl]; //
  36.  
  37. try
  38. {
  39. for (int i = 0; i < elements; i++) //
  40. {
  41. System.out.println("Enter " + (i + 1) + " element");
  42. BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "Cp1251"));
  43. String q = br.readLine();
  44. analys_elements(q);
  45. }
  46.  
  47. System.out.println("C = ");
  48. for(int i = 0; i < uzl; i++)
  49. {
  50. for(int j = 0; j < uzl; j++)
  51. {
  52. System.out.print(C[i][j] + " ");
  53. }
  54. System.out.println();
  55. }
  56.  
  57. System.out.println("G = ");
  58. for(int i = 0; i < uzl; i++)
  59. {
  60. for(int j = 0; j < uzl; j++)
  61. {
  62. System.out.print(G[i][j] + " ");
  63. }
  64. System.out.println();
  65. }
  66.  
  67. System.out.println("L = ");
  68. for(int i = 0; i < uzl; i++)
  69. {
  70. for(int j = 0; j < uzl; j++)
  71. {
  72. System.out.print(L[i][j] + " ");
  73. }
  74. System.out.println();
  75. }
  76.  
  77.  
  78.  
  79. System.out.println("X = ");
  80. for(int i = 0; i < uzl; i++)
  81. {
  82. System.out.println(X[i]);
  83. }
  84.  
  85. System.out.println("U = ");
  86. for(int i = 0; i < uzl; i++)
  87. {
  88. System.out.println(U[i]);
  89.  
  90. }
  91.  
  92. }
  93. catch (Exception e)
  94. {
  95. System.out.println(e);
  96. e.printStackTrace();
  97. }
  98.  
  99.  
  100. }
  101.  
  102. public static void analys_elements(String input) throws Exception
  103. {
  104.  
  105.  
  106.  
  107. int count_pointers = 0; //
  108.  
  109. for (char element : input.toCharArray()){ //
  110. if (element == ' ')
  111. {
  112. count_pointers++;
  113. }
  114. }
  115.  
  116. int i, j; //
  117.  
  118.  
  119. int position_type = input.indexOf(" "); //
  120.  
  121. String type = input.substring(0, position_type); //
  122.  
  123. String sub1 = input.substring(position_type + 1, input.length()); //
  124.  
  125.  
  126. int position_value = sub1.indexOf(" "); //
  127. String str_position = sub1.substring(0, position_value); //
  128. double value = Double.parseDouble(str_position); //
  129.  
  130. String sub2 = sub1.substring(position_value + 1, sub1.length()); //
  131.  
  132.  
  133. if (count_pointers == 2)
  134. {
  135. i = Integer.parseInt(sub2); //
  136.  
  137. j = i;
  138. }
  139. else
  140. {
  141. int node1_position = sub2.indexOf(" "); //
  142. String str_node1_value = sub2.substring(0,node1_position ); //
  143. i = Integer.parseInt(str_node1_value); //
  144. //String sub3 = sub2.substring(node1_position + 1, sub2.length());
  145.  
  146. int node2_position = sub2.indexOf(" "); //
  147. String sub3 = sub2.substring(node2_position + 1, sub2.length()); //
  148. }
  149.  
  150.  
  151. switch (type)
  152. {
  153. case "U":
  154. U[i-1] = value;
  155. break;
  156. case "C":
  157. if (count_pointers == 2 )
  158. {
  159. C[i-1][j-1] = value;
  160. }
  161. else
  162. {
  163. C[i-1][i-1] = value;
  164. C[j-1][j-1] = value;
  165. C[i-1][j-1] = -1 * value;
  166. C[j-1][i-1] = -1 * value;
  167. }
  168. break;
  169. case "Y":
  170. if (count_pointers == 2 )
  171. {
  172. G[i-1][j-1] = value;
  173. }
  174. else
  175. {
  176. G[i-1][i-1] = value;
  177. G[j-1][j-1] = value;
  178. G[i-1][j-1] = -1 * value;
  179. G[j-1][i-1] = -1 * value;
  180. }
  181. break;
  182. case "Yb":
  183. if (count_pointers == 2 )
  184. {
  185. G[i-1][j-1] = value;
  186. }
  187. else
  188. {
  189. G[i-1][i-1] = value;
  190. G[j-1][j-1] = value;
  191. G[i-1][j-1] = -1 * value;
  192. G[j-1][i-1] = -1 * value;
  193. }
  194. U[i-1] *= value;
  195. break;
  196. case "L":
  197. if (count_pointers == 2 )
  198. {
  199. L[i-1][j-1] = value;
  200. }
  201. else
  202. {
  203. L[i-1][i-1] = 1 / value;
  204. L[j-1][j-1] = 1 / value;
  205. L[i-1][j-1] = -1 / value;
  206. L[j-1][i-1] = -1 / value;
  207. }
  208. break;
  209. }
  210.  
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement