-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCalculate_The_Sum_By_Rotate.java
More file actions
52 lines (47 loc) · 1.29 KB
/
Calculate_The_Sum_By_Rotate.java
File metadata and controls
52 lines (47 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
public class Calculate_The_Sum_By_Rotate {
public static void RotateArr(int n,int[] arr)
{
for (int j = 0; j < n; j++) {
int len=arr.length;
int temp=arr[len-1];
for (int i = len-2; i >=0; i--) {
arr[i+1]=arr[i];
}
arr[0]=temp;
}
// print(arr);
}
public static void print(int[] arr){
for (int n:arr) {
System.out.print(n+" ");
}
System.out.println();
}
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int arr[]=new int[n];
for (int i = 0; i < n; i++) {
arr[i]=s.nextInt();
}
int t=s.nextInt();
int test[]=new int[t];
for (int i = 0; i < t; i++) {
test[i]=s.nextInt();
}
int arr2[]=arr.clone();
for (int p:test ) {
RotateArr(p,arr);
for (int i = 0; i < arr.length ; i++) {
arr[i]+=arr2[i];
}
arr2=arr;
}
int sum=0;
for (int i = 0; i < arr.length; i++) {
sum+=arr[i];
}
System.out.println(sum % (int) (Math.pow(10,9)+7) );
}
}