File tree Expand file tree Collapse file tree 2 files changed +102
-0
lines changed Expand file tree Collapse file tree 2 files changed +102
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+
3
+ class BuySell
4
+ {
5
+ public static void main (String args [])
6
+ {
7
+ Scanner in =new Scanner (System .in );
8
+
9
+ System .out .println ("Enter the size of the array" );
10
+ int size =in .nextInt ();
11
+
12
+ int arr []=new int [size ];
13
+
14
+ for (int k =0 ;k <size ;k ++)
15
+ {
16
+ System .out .println ("Enter the stock price at day" +k );
17
+ arr [k ]=in .nextInt ();
18
+ }
19
+
20
+ int buyDay =0 ;
21
+ int sellDay =0 ;
22
+
23
+ int k =0 ;
24
+
25
+ int m =k +1 ;
26
+ int nextBuyDay =m ;
27
+
28
+ while (m <size )
29
+ {
30
+ int big =arr [k ];
31
+ buyDay =k ;
32
+
33
+ int flag =0 ;
34
+
35
+ while (m <size )
36
+ {
37
+ if (arr [m ]>big )
38
+ {
39
+ big =arr [m ];
40
+ sellDay =m ;
41
+ }
42
+ else
43
+ {
44
+ nextBuyDay =m ;
45
+ flag =1 ;
46
+ break ;
47
+ }
48
+ m ++;
49
+ k ++;
50
+ }
51
+
52
+ if (buyDay !=sellDay )
53
+ System .out .println ("buy at day " +buyDay +" and sell at day " +sellDay );
54
+ if (flag ==1 )
55
+ {
56
+ k =nextBuyDay ;
57
+ m =k +1 ;
58
+ }
59
+
60
+
61
+ }//while
62
+
63
+ }
64
+
65
+ }
Original file line number Diff line number Diff line change
1
+ //reversing the order of terms of an algebraic expression that contains only 4 basic math operators without changing the order and the number itself e.g for input "5+6*7-60" output should be "60-7*6+5"
2
+
3
+ class One
4
+ {
5
+ public static void main (String args [])
6
+ {
7
+
8
+ String str =args [0 ];
9
+ String reverse ="" ;
10
+
11
+ int pos =str .length ()-1 ;
12
+
13
+ String term ="" ;
14
+
15
+ for (int k =0 ;k <str .length ();k ++)
16
+ {
17
+ char ch =str .charAt (pos --);
18
+
19
+ switch (ch )
20
+ {
21
+ case '-' :
22
+ case '+' :
23
+ case '/' :
24
+ case '*' :
25
+ reverse =reverse +term +ch ;
26
+ term ="" ;
27
+ break ;
28
+ default :
29
+ term =ch +term ;
30
+ }
31
+
32
+ }
33
+
34
+ System .out .println ("reverse is " +(reverse +term ));
35
+ }
36
+
37
+ }
You can’t perform that action at this time.
0 commit comments