Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. try {
  8.  
  9. double ar[]= new double[10];
  10. int thesh[]=new int[10];
  11. Scanner input=new Scanner(new File("C:/software/practise/src/hydrocarbons.in"));
  12. int oik =input.nextInt();
  13. int pl =-1;
  14. int j =-1;
  15. double t =0;
  16. while (input.hasNext())
  17. {
  18. int a=input.nextInt();
  19. int b=input.nextInt();
  20. int c=input.nextInt();
  21. t=a-a*(b/3000)-c*a/40;
  22. j++;
  23.  
  24. if(t>0)
  25. {
  26. pl++;
  27. ar[pl]=t;
  28. thesh[pl]=j+1;
  29. }
  30. }
  31. boolean f=true;
  32. //System.out.println(Arrays.toString(ar));
  33. //System.out.println(Arrays.toString(thesh));
  34. System.out.print(pl);
  35. int k =1;
  36. int temp=0;
  37. double temp2=0;
  38. while (k<=pl & f==true) {
  39. f=false;
  40. for (int i = pl-1; pl-1 >=k; i--)
  41. {
  42. if(ar[i]>ar[i-1] || (ar[i]==ar[i-1] & thesh[i]<thesh[i-1]))
  43. {
  44. f=true;
  45. System.out.print(f);
  46. temp2=ar[i];
  47. ar[i]=ar[i-1];
  48. ar[i-1]=temp2;
  49. temp=thesh[i];
  50. thesh[i]=thesh[i-1];
  51. thesh[i-1]=temp;
  52. System.out.println(Arrays.toString(ar));
  53. System.out.println(Arrays.toString(thesh));
  54. System.out.print(k);
  55.  
  56.  
  57. }
  58.  
  59. }
  60. k++;
  61. }
  62. System.out.println(Arrays.toString(ar));
  63. System.out.println(Arrays.toString(thesh));
  64. try
  65. {
  66. File file = new File("C:/software/practise/src/hydrocarbons.out");
  67. FileWriter fw = new FileWriter(file);
  68. PrintWriter pw = new PrintWriter(fw);
  69. pw.println(pl);
  70. for(int i=0; i<=pl;i++)
  71. {
  72. System.out.println(Arrays.toString(thesh));
  73. pw.println(thesh[i]);
  74. }
  75. pw.close();
  76. }
  77. catch (Exception ex){}
  78. input.close();
  79. }
  80. catch (Exception ex){}
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement