python 算术右移_Python算术序列| 竞争编码问题

python 算术右移

Question:

题:

In mathematics, when in an arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant then it is called arithmetic constant.

在数学中,当在算术序列中是一个数字序列,使得连续项之间的差为常数时,则称为算术常数。

Eric was writing an arithmetic sequence with N terms, but while writing he mistakenly made one wrong entry and he is sure that the first term is right. Help him to find the wrong term entered by him.

埃里克(Eric)正在写一个带有N个项的算术序列,但是在写时他错误地输入了错误的单词,并且他确信第一个项是正确的。 帮助他找到他输入的错误术语。

Input:

输入:

The first line of input contains a single line T, which represents the numbers of test cases. Then the first line of each test case contains an integer N total number of terms. And, then N space-separated integers denoting the sequence.

输入的第一行包含一行T ,代表测试用例的数量。 然后,每个测试用例的第一行包含一个整数N-项总数。 然后,用N个空格分隔的整数表示该序列。

    Test Cases: 2
5
1 3 5 6 9
4
1 2 3 5

Output:

输出:

For each test case, print the wrongly entered term.

对于每个测试用例,请打印输入错误的术语。

    6
5

Constraints:

限制条件:

    1<=T<=100
4<=N<=1000
1<=Terms<=1000

Explanation:

说明:

In this question, the arithmetic sequence is given and we have to find the wrong input sequence number. So firstly we find the common difference between the sequence which is constant in arithmetic sequence and then check the sequence and find the wrong number. Mainly in this question the focus on the arithmetic sequence(AP).

在这个问题中,给出了算术序列 ,我们必须找到错误的输入序列号。 因此,首先我们要找到在算术序列中恒定的序列之间的共同差异,然后检查序列并找到错误的数字。 这个问题主要集中在算术序列(AP)上。

To solve this question, we are using Python3.

为了解决这个问题,我们使用Python3。

Code:

码:

# Input test cases
print("Enter test cases (T): ")
t = int(input())
while (t > 0):
t -= 1
print("Enter number of elements (N): ")
N = int(input())
print("Enter elements separated by spaces: ")
arr = list(map(int, input().split()))
# assign the values of array in different variables
a = arr[0]
b = arr[1]
c = arr[2]
d = arr[3]
# compare the difference between the array element
if (b - a == c - b): #find common difference
diff = b - a
elif(c - b == d - c):
diff = c - b
else :
diff = d - a //3;
ref = arr[0]
#compare common difference with the array elements
for i in range(1, N): 
if (ref + diff == arr[i]):
ref = ref + diff
#print the wrong element in array
else :
print("Wrong term/number: ")
print(arr[i])
break

Output

输出量

Enter test cases (T): 
3
Enter number of elements (N): 
5
Enter elements separated by spaces: 
1 3 5 8 9
Wrong term/number: 
8
Enter number of elements (N): 
5
Enter elements separated by spaces: 
10 20 30 35 50
Wrong term/number: 
35
Enter number of elements (N): 
7
Enter elements separated by spaces: 
11 22 33 44 55 67 77
Wrong term/number: 
67

翻译自: https://www.includehelp.com/python/arithmetic-sequences-competitive-coding-questions.aspx

python 算术右移

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542359.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android8内测申请,小米 6 安卓 8.0 来了 内测开始招募

Android 8.0 已经正式发布多时&#xff0c;目前不少厂商已经启动了旗下进行的 Android 8.0 适配计划。但令人纳闷的是&#xff0c;一向对系统升级比较热心的小米却迟迟没有动静。好消息是&#xff0c;此前网友曝光的消息显示&#xff0c;MIUI 已经悄然在官方论坛中招募小米 6 的…

My linux

为什么80%的码农都做不了架构师&#xff1f;>>> 1.linux 命令方式修改机器名称 # hostname newHostName # vi /etc/sysconfig/network 修改或增加配置&#xff1a;hostnamenewHostName # vi /etc/hosts 修改对应的本地HOST映射 xx.xxx.xxx.xxx newHostName 2.Redha…

狂神说es笔记_人教版七上英语Unit5电子课本音频+课堂笔记+课后同步习题

1人教 七上英语Unit5单词七年级英语上册Unit 5单词默写1做&#xff1b;干(助动词)__________2做&#xff0c;干(助动词第三人称单数形式)__________3有__________4网球__________5球__________6乒乓球______7球棒&#xff1b;球拍__________8(英式)足球____________________9排…

Java RandomAccessFile getFilePointer()方法与示例

RandomAccessFile类getFilePointer()方法 (RandomAccessFile Class getFilePointer() method) getFilePointer() method is available in java.io package. getFilePointer()方法在java.io包中可用。 getFilePointer() method is used to get the current pointer in the Rando…

先进技术android,React Native实战(JavaScript开发iOS和Android应用)/计算机科学先进技术译丛...

导语内容提要本书作者Nader Dabit是AWS Mobile开发人员、React Native Training创始人和React Native Radio播客主持人。本书旨在帮助iOS、Android和Web开发人员学习使用React Native框架&#xff0c;构建高质量的iOS和Android应用程序。书中介绍了React Native入门基础知识&am…

开发类似vs的黑色风格_传闻:2020年《使命召唤》将是《黑色行动》重启作品

据可信度较高的消息源透露&#xff0c;2020 年的《使命召唤》将是《黑色行动》的重启作。而据之前的报道&#xff0c;《黑色行动》开发商 Treyarch 正在开发今年的《使命召唤》&#xff0c; Sledgehammer Games 和 Raven Software 负责辅助工作。该项目代号为“宙斯”&#xff…

ubuntu中 不同JDK版本之间的切换

Ubuntu中JDK 的切换前提是同时安装了多个版本&#xff0c;如jdk7和jdk8&#xff0c;若要切换&#xff0c;在终端输入&#xff1a; sudo update-alternatives --config javasudo update-alternatives --config javac

osi模型:七层模型介绍_联网| OSI模型能力问题和解答 套装1

osi模型:七层模型介绍1) There are the following statements that are given below, which of them are correct about the OSI model? The OSI model is a reference model that describes the network functionalities.The OSI model is an implemented model that describ…

华为鸿蒙系统正式登场,华为自研鸿蒙系统将于8月9日正式登场,还有全新的鸿鹄芯片...

最近华为发布了很多手机&#xff1a;荣耀20系列手机、荣耀9X系列、华为Nova 5系列&#xff0c;以及7月26日发布的华为Nova5i Pro和华为首部5G手机Mate20 X 5G版&#xff0c;这些手机将成为华为下半年的出货主力&#xff0c;市场份额能否超过50%就看这些手机的表现了。华为还将在…

pythonencode和decode_Python3的decode()与encode()

python3的decode()与encode()Tags: Python Python3对于从python2.7过来的人&#xff0c;对python3的感受就是python3对文本以及二进制数据做了比较清晰的区分。文本总是Unicode,由str类型进行表示&#xff0c;二进制数据使用bytes进行表示&#xff0c;不会将str与bytes偷偷的混…

微信小程序 开发 微信开发者工具 快捷键

微信小程序已经跑起来了.快捷键设置找了好久没找到,完全凭感觉.图贴出来.大家看看. 我现在用的是0.10.101100的版本,后续版本更新快捷键也应该不会有什么变化. 现在貌似不能修改.如果有同学找到修改的方法,麻烦告诉我.谢谢. 微信小程序代码编辑快捷键 常用快捷键 格式调整 Ctrl…

java 根据类名示例化类_Java MathContext类| 带示例的getRoundingMode()方法

java 根据类名示例化类MathContext类的getRoundingMode()方法 (MathContext Class getRoundingMode() method) getRoundingMode() method is available in java.math package. getRoundingMode()方法在java.math包中可用。 getRoundingMode() method is used to get the Roundi…

python中xy坐标如何从十个中找到最远的两个_python – Opencv单应性从像素xy坐标中查找全局xy坐标...

我试图找到变换矩阵H,以便我可以乘以(x,y)像素坐标并得到(x,y)真实世界坐标.这是我的代码&#xff1a;import cv2import numpy as npfrom numpy.linalg import invif __name__ __main__ :D[159.1,34.2]I[497.3,37.5]G[639.3,479.7]A[0,478.2]# Read source image.im_src cv2.…

[Android] Android统计Apk , jar包方法数

reference to : http://www.jianshu.com/p/61e8f803e0d1 Android在开发过程中&#xff0c;随着引用的库以及业务的增多&#xff0c;不可避免的会出现64K limit问题&#xff0c;也就是方法数过多的问题&#xff0c;Java代码中的Method总数和Field总数都不能超过65535个&#xff…

type c pin定义_在C中定义宏以设置和清除PIN的位

type c pin定义Given a PIN (value in HEX) and bit number, we have to SET and then CLEAR given bit of the PIN (val) by using Macros. 给定一个PIN(十六进制值)和位数&#xff0c;我们必须使用宏将SET(设置)&#xff0c;然后清除给定的PIN(值)位(值)。 Macros definitio…

android9有深色模式吗,深色模式还是黑色模式?微信把所有人都搞懵了

原标题&#xff1a;深色模式还是黑色模式&#xff1f;微信把所有人都搞懵了前一阵子&#xff0c;微信正式加入了对“深色模式”的支持&#xff0c;这也是除了Windows Phone 版本以外微信第一次从系统层面支持深色模式。虽然这次更新离WWDC上的演示已经过去了9个月&#xff0c;但…

网站后端_Python+Flask.0007.FLASK构造跳转之301跳转与302重定向?

构造地址:说明: FLASK支持通过视图函数及传参来构造URL,而且未来修改URL可一次性修改,且默认构建会转义特殊字符和Unicode数据,这些工作不需要我们自己处理,且不仅支持在上下文中构造而且还支持在模版文件中构造#!/usr/bin/env python # -*- coding: utf-8 -*- ""&qu…

python插值程序_计算方法(2)——插值法(附Python程序)

给定一些数据&#xff0c;生成函数的方式有两种&#xff1a;插值&#xff0c;回归。插值而得到的函数通过数据点&#xff0c;回归得到的函数不一定通过数据点。下面给出拉格朗日插值&#xff0c;牛顿插值和Hermite插值的程序&#xff0c;具体原理可参考课本&#xff0c;不再赘述…

java中cbrt_Java Math类静态double cbrt(double d)示例

java中cbrt数学类静态double cbrt(double d) (Math Class static double cbrt(double d)) This method is available in java.lang package. 此方法在java.lang包中可用。 This method is used to find the cube root of the given parameter in the method. 此方法用于查找方法…

html中电子邮件怎么写,谈html mailto(电子邮件)实际应用

大家知道&#xff0c;mailto是网页设计制作中的一个非常实用的html标签&#xff0c;许多拥有个人网页的朋友都喜欢在网站的醒目位置处写上自己的电子邮件地址&#xff0c;这样网页浏览者一旦用鼠标单击一下由mailto组成的超级连接后&#xff0c;就能自动打开当前计算机系统中默…