招行信用卡笔试,编程题求解答

1.输出是否为回文字符串,1-》1,2—》5,3-》8.。。。
import sys
if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    dict = {'1': '1', '2': '5', '3': '8', '4': '7', '6': '9'}
    for i in range(n):
        read = sys.stdin.readline().strip()
        i = 0
        j = len(read) - 1
        while (i < j):
            if dict[read[i]] == read[j]:
                i += 1
                j -= 1
            else:
                break
        if i >= j:
            print('YES')
        else:
            print('NO')
通过0%。。。
2.输入n
输入n行------数字串         k 
判断数字串通过几种加减操作==k
import sys
if __name__ == "__main__":
    # 读取第一行的n
    n = int(sys.stdin.readline().strip())
    for i in range(n):
        # 读取每一行
        result = []
        line = sys.stdin.readline().strip()
        values,k = line.split()
        k = int(k)
        values = list(map(int,list(values)))
        result.append(values.pop(0))
        while(len(values)!=0):
            temp = values.pop(0)
            # print(values)
            re = result[:]
            for i,num in enumerate(result):
                numa = num+temp
                numb = num-temp
                re.append(numa)
                re.append(numb)
                del re[i]
            result = re[:]
        count = 0
        for i in result:
            if i==k:
                count += 1
        print(count)



#招商银行信用卡中心2020春招##招商银行信用卡中心##笔试题目#
全部评论
&第一题里面,需要单独考虑1,单独一个1是镜像,如果是奇数长度,中间是1才能是镜像。边界条件需要考虑周全
3 回复
分享
发布于 2020-04-08 21:06
第二题ac代码
3 回复
分享
发布于 2020-04-08 21:25
百信银行
校招火热招聘中
官网直投
第一题的字典里把1-9全部写上
1 回复
分享
发布于 2020-04-08 21:03
线下都可以,线上全是0%。。。
点赞 回复
分享
发布于 2020-04-08 20:57
import java.util.Scanner; public class Main{ static int max=-1; public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); String str[]=new String[n]; int rs[]=new int[n]; for(int i=0;i<n;i++) { str[i]=s.next(); rs[i]=s.nextInt(); } for(int i=0;i<n;i++) { max=0; f(str[i].substring(1),rs[i],Integer.parseInt(str[i].substring(0,1))); System.out.println(max); } } public static void f(String str,int num,int count) { if(count==num&&str.equals("")) { System.out.println(str); max++; return; } for(int i=0;i<str.length();i++) { int a=Integer.parseInt(str.substring(i, i+1)); for(int j=0;j<2;j++) { if(j==0) { count=count+a; f(str.substring(i+1),num,count); count=count-a; }else { count=count-a; f(str.substring(i+1),num,count); count=count+a; } } } return; } } 第二题为啥不行啊,求教
点赞 回复
分享
发布于 2020-04-08 21:00
哎,我也是线上是0,我以为是题目的问题,可是我看到牛客上有大佬A了,很难受
点赞 回复
分享
发布于 2020-04-08 21:02
第二题A了吗?我第一题过了90%,第二题样例过了,线上0.。。
点赞 回复
分享
发布于 2020-04-08 21:08
我好菜啊
点赞 回复
分享
发布于 2020-04-08 21:11
&为啥我线上是0%???好气啊
点赞 回复
分享
发布于 2020-04-08 21:12
&第二题是每个中间位置有3种情况,加号,减号,以及什么都不加,然而还是没过😔
点赞 回复
分享
发布于 2020-04-08 21:15
第二题我以为每两个数字之间都要加符号,其实可以不加的。我晕了
点赞 回复
分享
发布于 2020-04-08 21:16
第一题A了 第二题0 dic = {1: 1, 2: 5, 3: 8, 4: 7, 5: 2, 6: 9, 7: 4, 8: 3, 9: 6} N = int(input().strip()) for _ in range(N):     in_list = list(map(lambda x: int(x), [_ for _ in input()]))     t_list = list(map(lambda i: dic[i], in_list))     re_list = in_list[::-1]     if re_list == t_list:         print("YES")     else:         print("NO")
点赞 回复
分享
发布于 2020-04-08 21:17
&第一题A了,第二题测了好多次数据过了,但是线上还是0,求解
点赞 回复
分享
发布于 2020-04-08 21:20
招行笔试多少能过啊,第一题ac了100,第二题0,其他就靠选择题拿点分
点赞 回复
分享
发布于 2020-04-08 21:20
啊!我第一题A了10% 我看错题目了 我以为对应的数除了1之外差值的绝对值都为3 ??? 我的天呀我在想什么
点赞 回复
分享
发布于 2020-04-08 21:28
第二题不一定每个位置都有符号的,想过来这个应该就可以了
点赞 回复
分享
发布于 2020-04-08 21:30
虽然还没收到笔试通知,先 mark 一波。
点赞 回复
分享
发布于 2020-04-09 11:36

相关推荐

点赞 9 评论
分享
牛客网
牛客企业服务