360编程题

第一题:
#!/bin/python
# -*- coding: utf8 -*-
import sys
import os
import re


# 请完成下面这个函数,实现题目要求的功能
# 当然,你也可以不按照下面这个模板来作答,完全按照自己的想法来 ^-^
# ******************************开始写代码******************************


def string2int(str):
    check = ''
    if '.' in str:
        #小数
        arr = str.split('.')
        for con in arr:
            if con.isdigit():
                check+='1'
            else:
                check+='2'

        for i in check:
            if i != '1':
                return 0
        if len(arr) == 2:
            num = arr[0]
            return int(num)
        else:
            #不合法,包含多个点的情况
            return 0
    else:
        #整数
        is_num = re.findall('\d', str)
        if len(str) != len(is_num):
            return 0
        if len(str) == 0:
            return 0
        return int(str)


# ******************************结束写代码******************************


try:
    _str = input()
except:
    _str = None

res = string2int(_str)

print(str(res) + "\n")

第二题:





#!/bin/python # -*- coding: utf8 -*- 
import sys 
import os 
import re 
# 请完成下面这个函数,实现题目要求的功能 # 当然,你也可以不按照下面这个模板来作答,完全按照自己的想法来 ^-^ 
# ******************************开始写代码******************************   
def f(num):
    c = 0  
    temp = num % 3  
        if temp == 0:
            c += 1  
            # c = math.log(num, 3)  
            c += f(num // 3)
        return c # res  =f(6) # print(res) 
def main(): 
    n = int(input())
    arr = input().split(' ')
    arr_num = list(map(int, arr))
    res_num = [] 
    for num in arr_num:
        res_num.append(f(num))
        res_num = list(map(int, res_num)) 
    return sum(res_num) 
# ******************************结束写代码******************************   
res = main() 
print(str(res) + "\n")



#360公司##笔试题目#
全部评论
第一道,说了不让用int()
点赞 回复
分享
发布于 2019-04-24 22:12

相关推荐

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