首页 > 其他分享 >鼎利杯练习题

鼎利杯练习题

时间:2023-04-16 18:11:44浏览次数:33  
标签:练习题 鼎利杯 nums break range time print total

第一题

moves = input()
x, y = 0, 0
for move in moves:
    if move == "L":
        x -= 1
    elif move == "R":
        x += 1
    elif move == "U":
        y += 1
    elif move == "D":
        y -= 1
if x == 0 and y == 0:
    print('true')
else:
    print('false')

第二题

target = input()
nums = [2, 7, 11, 15]
lens = len(nums)
jieguo = False
for i in range(lens):
    for j in range(i+1, lens):
        if nums[j] + nums[i] == int(target):
            x = [i, j]
            jieguo = True
            print(x)
            break
    if jieguo:
        break

第三题

感觉有问题,还没做

第四题

nums = [4, 1, 2, 0]
x = len(nums) + 1
for i in range(x):
    n = 0
    for j in nums:
        if i == j:
            n = 1
            break
    if n == 0:
        print(i)
        break

第五题

还有点问题

num = 30
n, x = 0, 0
for i in range(1, num+1):
    if (x + i % 10) % 2 == 0:
        n += 1
        x += i
        print(i, end=' ')
print('\n', n)

第六题

timePoints = ["01:00","02:00","04:00"]
min_m = 9999
for i in range(len(timePoints) - 1):
    one = timePoints[i].split(':')
    two = timePoints[i + 1].split(':')
    time_1, time_2 = int(one[0]), int(two[0])
    minute_1, minute_2 = int(one[1]), int(two[1])
    if time_1 == 0:
        time_1 = 24
    if time_2 == 0:
        time_2 = 24
    time_1, time_2 = time_1*60, time_2*60
    o = time_1 + minute_1
    t = time_2 + minute_2
    x = t - o
    if x <min_m:
        if x < 0:
            x *= -1
        min_m = x
print(min_m)

第七题

nums1, nums2 = [4,9,5], [9,4,9,8,4]
x = []
for i in nums1:
    for j in nums2:
        if j in x :
            break
        if i == j:
            x.append(j)
print(x)

第八题

nums = [-1,0,3,5,9,12]
target = 9
x = False
for i in range(len(nums)):
    if target == nums[i]:
        print(i)
        x = True
        break
if not x:
    print(-1)

第九题

circles = [[2,2,2],[2,2,5]]
n = 0
gezi = []
for o in circles:
    min_x = o[0] - o[2]
    max_x = o[0] + o[2]
    min_y = o[1] - o[2]
    max_y = o[1] + o[2]
    n_r = 2*o[2] + 1
    for x in range(min_x, max_x + 1):
        for y in range(min_y, max_y + 1):
            total_x = (x - o[0])
            total_y = (y - o[1])
            if total_x < 0:
                total_x *= -1
            if total_y < 0:
                total_y *= -1
            long = pow(total_x ** 2 + total_y ** 2, 0.5)
            if long <= o[2]:
                if not [x,y] in gezi:
                    gezi.append([x,y])
                    n += 1
print(n)

标签:练习题,鼎利杯,nums,break,range,time,print,total
From: https://www.cnblogs.com/aduiduidui/p/17323733.html

相关文章

  • C++第二章课后练习题 2-24,2-25
    编写一个完整的程序,实现功能:向用户提问“现在正在下雨吗?”,提示用户输入Y或N。若输入为Y,显示“现在正在下雨。”;若输入为N,显示“现在没有下雨。”;否则继续提问“现在正在下雨吗?”。#include<iostream>usingnamespacestd;intmain(){cout<<"现在正在下雨吗?"<<endl;......
  • 天梯赛练习题 L3-008 喊山(bfs)
    https://pintia.cn/problem-sets/994805046380707840/exam/problems/994805050709229568输入样例:75412233145561457输出样例:2640#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpair<LL,LL>PII;constLLMAX......
  • 天梯赛练习题 L3-004 肿瘤诊断(bfs)
    https://pintia.cn/problem-sets/994805046380707840/exam/problems/994805052626026496输入样例:3452111111111111001100110011101101000000101100000000000100011000输出样例:26LLdz[]={1,-1,0,0,0,0},dx......
  • CSAPP练习题2.11
    练习题2.111/*2CSAPP练习题2.11,并做了一些扩展3指定或者用户输入一个数组(100以内),打印反转前后的所有数组元素4*/5#include<stdio.h>67voidinplace_swap(int*x,int*y);//互换值8voidreverse_array(inta[],intcnt);//数组反转9voi......
  • java -- 练习题
    第一题1.定义一个Person类,要求有姓名和年龄,并且符合JavaBean标准,定义Student类继承Person,定义测试类,创建Student对象,要求创建Student对象的同时,指定Student对象的姓名为"张三",只能指定姓名不许指定年龄classPerson{privateStringname;privateintage;......
  • mysql 查询练习题
    1.查出至少有一个员工的部门。显示部门编号、部门名称、部门位置、部门人数。selectd.deptno,d.dname,d.loc,r.countfromdeptd,(selectdeptno,count(*)countfromempgroupbydeptno)rwhered.deptno=r.deptno;2.列出薪金比smith高的所有员工。select*fro......
  • 结对编程——四则运算练习题
    结对编程题目如下:小学老师要每周给同学出300道四则运算练习题。这个程序有很多种实现方式:C/C++C#/VB.net/JavaExcelUnixShellEmacs/Powershell/VbscriptPerlPython一个或两个运算符(a+b或a+b+c),100以内的数字,不需要写答案。需要检查答案是否正确,并且保证答案在0......
  • NFS练习题
    NFS练习题1.开放/nfs/share目录,提供给任意用户只读(/etc/exportsro)查询1.任意客户端2.任意的用户​​​​ 服务端showmoutexportfssystemctlstartnfs 修改了nfs配置文件,需要重启什么吗?修改了nfs配置文件,只需要让nfs重新读取该配置文件即可,你都不需要重新,因为你......
  • C++ Primer 第五版 第十一章 练习题编程题目答案
    https://github.com/jzplp/Cpp-Primer-Answer练习11.1map用关键字索引,是一个字典。vector用整数索引,是一个列表。练习11.2list链表vector顺序列表deque双端队列map字典set集合练习11.311.3map单词计数程序代码练习11.411.4去标点map单词计数程序代码练习11.5如果关键......
  • A模块练习题
    mysql练习题1.查找数据库版本号mysql>selectversion();2.查找数据库列表mysql>showtables;3.查看所有用户和权限,找到可以从任意IP地址访问mysql>showgrantsforroot@localhostmysql>selectdistinctconcat('user:''',user,'''@''',......