zoukankan      html  css  js  c++  java
  • 七牛云笔试题-2019-10

    1、两数和问题

    """

    def solution(arr,length,sum):
    dic = {}
    for i in range(length):
    t = sum-arr[i]
    if arr[i] in dic:
    return "{} {}".format(dic[arr[i]],i)
    else:
    dic[t] = i
    return -1

    length = int(input())
    arr = list(map(int,input().split(" ")))
    sum = int(input())
    print(solution(arr,length,sum))

    """

    2、括号匹配问题

    """

    def solution(s):
    li = []
    for i in s:
    if i == "(" or i == "(" or i == "[" or i == "{" or i == "<":
    li.append(i)
    else:
    if not li:
    return False
    pre = li.pop()
    if (pre == "(" and i == ")") or (pre == "[" and i == "]") or (pre == "{" and i == "}") or (
    pre == "<" and i == ">"):
    continue
    else:
    return False
    if not li:
    return True

    s = input()
    print(solution(s))
    """

    3、数字出现的第一个位置和最后一个位置

    """

    def solution(arr,n,target):
    pre = -1
    next = -1
    for i in range(n):
    if arr[i] == target:
    if pre == -1:
    pre = i
    next = i
    else:
    next = i
    return "%d %d" %(pre,next)

    n = int(input())
    arr = list(map(int,input().split(" ")))
    target = int(input())
    print(solution(arr,n,target))

    """

  • 相关阅读:
    web.config配置错误的后果
    重装VS.NET碰到:IDE 未能加载 Dte.olb
    初次使用Wix
    typedef
    [WTL] Accelerator
    在浏览器中粘贴时替换剪贴板数据
    自定义浏览器
    关于MSHTML
    [WTL] STLport安装指南
    [WTL] WTL7.5中CFileDialog用'\0'过滤
  • 原文地址:https://www.cnblogs.com/ChangAn223/p/11694743.html
Copyright © 2011-2022 走看看