I just can’t understand how to deal with it…please help
Calculate the sum((((()))))))
Hi @abhinavssr2003_eab0717682969e5c,
LOGIC :
u dont need to calculate the sum by shifting again and again, anyway u will be adding the array sum of that array only even if u shift and add as u r adding all the elements so dont shift just keep updating the sum of array
see here for implementation here’s the commented code https://ide.codingblocks.com/s/657171
sir but i want to do with the help of arrays
it is working like array only…but not with a[]…like i want to use proper array function so how should i implement it
@abhinavssr2003_eab0717682969e5c, what array functions you wanna use can you elaborate a little bit…
will you just modify my code
include
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
int t;
cin>>t;
while(t>0){
int no;
cin>>no;
no /= no%n;
int temp[n];
for (int i = 0; i < n; i++)
{
a[i] = temp[i];
}
for (int i = 0; i < n; i++)
{
temp[i] += temp[no];
}
}
return 0;
}
like i am not getting how to add the values…just help me in my code so that i can be clear…your earlier solution was cleared to me
i tried myself …plzz check
include
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for (int i = 0; i < n; i++)
{
cin>>a[i];
}
int t;
cin>>t;
while(t>0){
int no;
cin>>no;
no /= no%n;
int temp[n];
for (int i = 0; i < n; i++)
{
a[i] = temp[i];
}
for (int i = 0; i < n; i++)
{
temp[i] = a [i] + a[(i-no+n)%n];
}
for (int i = 0; i < n; i++)
{
temp[i] = a[i];
}
t--;
}
int sum = 0;
for(int i = 0 ; i<n ; i++){
sum+=a[i];
}
cout<<sum<<endl;
return 0;
}
anyone there?? please check…i m getting wrong result
hi @abhinavssr2003_eab0717682969e5c, check the updated code https://ide.codingblocks.com/s/659598, ive commented the mistakes
i just got my all test cases passed…but i have one more doubt…why line 24 is inc and 25 is corr…also why 35 is inc and 36 is corr??
@abhinavssr2003_eab0717682969e5c, the order is first you are storing in temp array doing the calculation in line 30 then again you r updating the original array, the mistake was due to those 2 statements the order was reversed
ohh got it…so can we do this problem without temp array??
okay thank you so much
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.