As usual Babul is again back with his problem and now with numbers. He thought of an array of numbers in which he does two types of operation that is rotation and deletion. His process of doing these 2 operations are that he first rotates the array in a clockwise direction then delete the last element. In short he rotates the array nth times and then deletes the nth last element. If the nth last element does not exists then he deletes the first element present in the array. So your task is to find out which is the last element that he deletes from the array so that the array becomes empty after removing it.

For example
A = {1,2,3,4,5,6}.
He rotates the array clockwise i.e. after rotation the array A = {6,1,2,3,4,5} and delete the last element that is {5} so A = {6,1,2,3,4}. Again he rotates the array for the second time and deletes the second last element that is {2} so A = {4,6,1,3}, doing these steps when he reaches 4th time, 4th last element does not exists so he deletes 1st element ie {1} so A={3,6}. So continuing this procedure the last element in A is {3}, so o/p will be 3.
 
Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two lines. The first line of each test case contains an integer N. Then in the next line are N space separated values of the array A.
 
Output:
For each test case in a new line print the required result.
 
Constraints:
1<=T<=200
1<=N<=100
1<=A[i]<=10^7
 
Example:
Input
2
4
1 2 3 4
6
1 2 3 4 5 6
Output:
2
3
### C++(gcc5.4)代码:
        #include <iostream>
        using namespace std;
        int main() {
        //code
       // define the number of test cases
       int T;
       cin>>T;
       
       for(int t=0; t<T; t++)
        {
           //get the two line input
           int N;
           cin>>N;
           int a[N];
           int i = 0;  
                for(i=0;i<N;i++)
               cin>>a[i];
        
                //Rotate and delete
                int index_delete = 1;
                int array_length = N;
                int tmp;
                while(array_length>1)  
                {
                    //Rotate
                    tmp = a[array_length - 1];
                    for(int j=array_length-1; j>0; j--)
                    {
                        a[j] = a[j-1];
                    }
                    a[0] = tmp;
                    
                    //delete
                    for(int k=array_length<index_delete?0:array_length-index_delete; k<array_length-1; k++)
                    {
                        a[k]=a[k+1];
                    }    
                    
                    index_delete += 1;
                    array_length -= 1; 
                }
                cout<<a[0]<<endl;
        }
       return 0;
        }
####注:更加严谨的将一行数字存入数组的代码如下,但是在测试时包含这部分代码的程序会提示超出时间限制!
·#include<iostream>  
using namespace std;  
int main()  
{  
    int a[50];  
    int i = 0;  
    char c;  
    while((c=getchar())!='\n')  
    {  
        if(c!=' ')//把这句判断条件改动  
        {  
            ungetc(c,stdin);  
            cin>>a[i++];  
        }  
    }  
    for(int j=0;j<i;j++)  
    {  
        cout<<"a["<<j<<"]:"<<a[j]<<endl;  
    }  
---
### python代码

geeksforgeeks-Array-Rotation and deletion的更多相关文章

  1. Data Structure Array: Program for array rotation

    http://www.geeksforgeeks.org/array-rotation/ O(n), O(1) #include <iostream> #include <vecto ...

  2. geeksforgeeks-Array-Rotate and delete

    As usual Babul is again back with his problem and now with numbers. He thought of an array of number ...

  3. Must practice programming questions in all languages

    To master any programming languages, you need to definitely solve/practice the below-listed problems ...

  4. geeksforgeeks@ Largest Number formed from an Array

    http://www.practice.geeksforgeeks.org/problem-page.php?pid=380 Largest Number formed from an Array G ...

  5. geeksforgeeks@ Sorting Elements of an Array by Frequency (Sort)

    http://www.practice.geeksforgeeks.org/problem-page.php?pid=493 Sorting Elements of an Array by Frequ ...

  6. [geeksforgeeks] Count the number of occurrences in a sorted array

    Count the number of occurrences in a sorted array Given a sorted array arr[] and a number x, write a ...

  7. Suffix array

    A suffix array is a sorted array of all suffixes of a given string. The definition is similar to Suf ...

  8. 算法最坏,平均和最佳情况(Worst, Average and Best Cases)-------geeksforgeeks 翻译

    最坏,平均和最佳运行时间(Worst, Average and Best Cases) 在上一篇文章中,我们讨论到了渐进分析可以解决分析算法的问题,那么在这一篇中,我们用线性搜索来举例说明一下如何用渐 ...

  9. 42.旋转数组的最小元素[Get min value of rotated array]

    [题目] 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个排好序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3, 4, 5, 1, 2}为{1, 2, 3, 4, 5 ...

随机推荐

  1. 浅析python日志重复输出问题

    浅析python日志重复输出问题 问题起源: ​ 在学习了python的函数式编程后,又接触到了logging这样一个强大的日志模块.为了减少重复代码,应该不少同学和我一样便迫不及待的写了一个自己的日 ...

  2. 棋盘问题 POJ - 1321

    题意: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放 ...

  3. MT【45】抛物线外一点作抛物线的切线(尺规作图题)

    注1:S为抛物线焦点 注2:由切线的唯一性,以及切线时可以利用MT[42]评得到三角形全等从而得到切线平分$\angle MQS$得到

  4. 8bit数据 转换为 16bit数据的四种方法

    [转]玩转嵌入式(公众号) 在入门单片机时,想必大家都都会遇到一下这种情况 unsigned char a = 0x12; unsigned char b = 0x34; unsigned int c ...

  5. redis中的数据类型

    redis不是一个纯文本kv存储,实际上,它是一个数据结构服务,支持不同类型的value. 包含以下类型: 1.Binary-safe strings. 二进制安全的字符串 2.Lists: coll ...

  6. linux已开机时间 系统信息

    linux 查看系统运行时间 (从开机当现在的开机时间) 1.uptime命令输出:16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0. ...

  7. Solr7.1--- 生产环境搭建

    准备三台虚拟机,把Solr-7.1.0.tgz上传到三个节点上.我上传到了自定义的目录/mysoft. 我的环境是CentOS7+Solr7.1.0 如果发现图文不符,因为我之前操作截图后,关闭出去吃 ...

  8. poj 1759(二分)

    传送门:Problem 1759 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N个彩灯关在同一条绳上,给出第一个彩灯的高度A,并给 ...

  9. InfluxDB1.2.4部署(centos6.8)

    InfluxDB介绍 官网:https://www.influxdata.com/ 文档:https://docs.influxdata.com/influxdb/v1.2/introduction/ ...

  10. Hadoop生态圈-Oozie部署实战

    Hadoop生态圈-Oozie部署实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Oozie简介 1>.什么是Oozie Oozie英文翻译为:驯象人.一个基于工作流 ...