File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ public class Calculate_The_Sum_By_Rotate {
4
+ public static void RotateArr (int n ,int [] arr )
5
+ {
6
+ for (int j = 0 ; j < n ; j ++) {
7
+ int len =arr .length ;
8
+ int temp =arr [len -1 ];
9
+ for (int i = len -2 ; i >=0 ; i --) {
10
+ arr [i +1 ]=arr [i ];
11
+ }
12
+ arr [0 ]=temp ;
13
+ }
14
+ // print(arr);
15
+ }
16
+ public static void print (int [] arr ){
17
+ for (int n :arr ) {
18
+ System .out .print (n +" " );
19
+ }
20
+ System .out .println ();
21
+ }
22
+ public static void main (String [] args ) {
23
+ Scanner s =new Scanner (System .in );
24
+ int n =s .nextInt ();
25
+ int arr []=new int [n ];
26
+ for (int i = 0 ; i < n ; i ++) {
27
+ arr [i ]=s .nextInt ();
28
+ }
29
+ int t =s .nextInt ();
30
+ int test []=new int [t ];
31
+ for (int i = 0 ; i < t ; i ++) {
32
+ test [i ]=s .nextInt ();
33
+ }
34
+ int arr2 []=arr .clone ();
35
+
36
+ for (int p :test ) {
37
+ RotateArr (p ,arr );
38
+ for (int i = 0 ; i < arr .length ; i ++) {
39
+ arr [i ]+=arr2 [i ];
40
+ }
41
+ arr2 =arr ;
42
+ }
43
+
44
+ int sum =0 ;
45
+ for (int i = 0 ; i < arr .length ; i ++) {
46
+ sum +=arr [i ];
47
+ }
48
+
49
+ System .out .println (sum % (int ) (Math .pow (10 ,9 )+7 ) );
50
+
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments