12:12 Akshit Grover,
Solution To First Problem:
Solution To First Problem:
Question:
John Watson performs an operation called a right circular rotation on an array of integers, . After performing one right circular rotation operation, the array is transformed from to .
Watson performs this operation times. To test Sherlock's ability to identify the current element at a particular position in the rotated array, Watson asks queries, where each query consists of a single integer for which you must print the element in the rotated array.
Solution:
#include <stdio.h>
void main()
{
int a[50],i,c,n,k,q;
input:
scanf("%d%d%d",&n,&k,&q);
if(q<=n)
{
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
for(c=1;c<=k;c++)
{
for(i=0;i<=n-2;i++)
{
a[0]=a[0]+a[i+1];
a[i+1]=a[0]-a[i+1];
a[0]=a[0]-a[i+1];
}
}
print("\n");
for(i=0;i<=q-1;i++)
{
printf("%d\n",a[i]);
}
}
else
goto input;
}
Output:
No comments:
Post a Comment