Problem 47

4 comments on “Problem 47”


  • GAURAV

    #include

    using namespace std;
    void rotate(int arr[],int l,int h){
    while(h>l){
    int temp=arr[l];
    arr[l]=arr[h];
    arr[h]=temp;
    l++;
    h–;
    }
    }

    int main()
    {
    int n;int d;
    int arr[n];
    cin>>n;
    cin>>d;
    for(int i=0;i>arr[i];
    }
    rotate(arr,0,n-d-1);
    rotate(arr,n-d,n-1);
    rotate(arr,0,n-1);
    cout<<arr[1];
    cout<<arr[2];
    return 0;
    }


  • shushank

    #Python Programming

    l=list(map(int,input().split(” “)))
    k=int(input())
    for i in range(k):
    a1=l[-1]
    l.insert(0,a1)
    l[:]=l[:len(l)-1]
    print(l)


  • Yogesh

    Solution from Yogesh Jadhav([email protected]):
    Under while loop by mistake k is k-; This not k- but correct as k–;

    public class ArrayShift
    {
    public static void main(String[] args) {
    int k=2;
    int ct=-1;
    int index=0;
    int a[]=new int[]{3,4,5};
    int b[]=new int[a.length];
    while(k>=1){
    for(int i=0;i<a.length;i++){
    ct++;
    if(i==a.length-1){
    b[index]=a[i];
    index++;
    }
    }
    for(int j=0;j<ct;j++){
    b[index]=a[j];
    index++;
    }
    for(int c=0;c<a.length;c++){
    a[c]=b[c];
    }
    k–;
    ct=-1;
    index=0;
    }
    for(int m=0;m<a.length;m++){
    System.out.print(a[m]);
    }
    }
    }


  • Yogesh

    Solution from Yogesh Jadhav([email protected]):
    public class ArrayShift
    {
    public static void main(String[] args) {
    int k=2;
    int ct=-1;
    int index=0;
    int a[]=new int[]{3,4,5};
    int b[]=new int[a.length];
    while(k>=1){
    for(int i=0;i<a.length;i++){
    ct++;
    if(i==a.length-1){
    b[index]=a[i];
    index++;
    }
    }
    for(int j=0;j<ct;j++){
    b[index]=a[j];
    index++;
    }
    for(int c=0;c<a.length;c++){
    a[c]=b[c];
    }
    k–;
    ct=-1;
    index=0;
    }
    for(int m=0;m<a.length;m++){
    System.out.print(a[m]);
    }
    }
    }