【CodinGame】趣味算法 CLASH OF CODE -20240722

简单判断

在这里插入图片描述
在这里插入图片描述


import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

b = int(input())
p = int(input())
r = int(input())
t = int(input())

if p*r*t < b:
    print("Enough bread")
if p*r*t == b:
    print("Just enough bread")
if p*r*t > b:
    print("Not enough bread")




计算2的幂总和

在这里插入图片描述

在这里插入图片描述

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

n = int(input())

# 计算2的幂总和
print(sum([2**i for i in range(n)]))



ascii求和

在这里插入图片描述
在这里插入图片描述

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

line = input()
sum_count = 0

for i in line:
    # 计算ascii
    sum_count += ord(i)

print(int(math.sqrt(sum_count)))


奇偶数索引

在这里插入图片描述

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

n = input()
ou_count = 0
ji_count = 0

for i , num in enumerate(n):
    if int(num)%2==0:
        ou_count += i
    else:
        ji_count += i

print(abs(ou_count - ji_count))

更优雅的写法(作者:norxondor_gorgonax)

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

n = input()


print(abs(sum(map(int, n[::2])) - sum(map(int, n[1::2]))))



大小写字母

在这里插入图片描述

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

s = input()

# 大写字母的数量
print(sum(1 for c in s if c.isupper()) ** sum(1 for c in s if c.islower()))

优雅写法(作者:norxondor_gorgonax)

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

s = input()

# Write an answer using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)

print(sum(map(str.isupper, s)) ** sum(map(str.islower, s)))



两数互质

在这里插入图片描述


import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

a = int(input())
b = int(input())

# 给定两个整数 a 和 b。对于这两个整数,我们寻找能除以 a 和 b 的正整数(不留余数)。如果除了 1 之外不存在这样的整数,我们称 a 和 b 互质。
print('true' if math.gcd(a, b) == 1 else 'false')

优雅(作者:norxondor_gorgonax)

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

a = int(input())
b = int(input())

# Write an answer using print
# To debug: print("Debug messages...", file=sys.stderr, flush=True)

print(str(math.gcd(a,b)==1).lower())



chr

在这里插入图片描述

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.

n = int(input())

# 1对应A,拿到对应字符
print(chr(64 + n)*n)

这里注意chr 是 Python 中的一个内置函数,用于将一个整数(通常是一个 Unicode 码点)转换为其对应的字符

END

相关推荐

  1. 趣味算法】13_素数

    2024-07-23 06:18:03       37 阅读
  2. 趣味算法】11_黑洞数

    2024-07-23 06:18:03       30 阅读
  3. 趣味算法】16_递归练习

    2024-07-23 06:18:03       24 阅读
  4. 20240222作业

    2024-07-23 06:18:03       38 阅读
  5. 趣味算法】00_百鸡百钱

    2024-07-23 06:18:03       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-23 06:18:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-23 06:18:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-23 06:18:03       45 阅读
  4. Python语言-面向对象

    2024-07-23 06:18:03       55 阅读

热门阅读

  1. 【Go程序】爬虫获取豆瓣Top250

    2024-07-23 06:18:03       14 阅读
  2. python入门课程Pro(2)--循环

    2024-07-23 06:18:03       14 阅读
  3. 深入剖析Tomcat整体架构

    2024-07-23 06:18:03       15 阅读
  4. CCF GESP Python编程 二级认证真题 2024年6月

    2024-07-23 06:18:03       19 阅读
  5. Android5.1 NAT功能的iptables规则

    2024-07-23 06:18:03       18 阅读
  6. C语言-预处理详解

    2024-07-23 06:18:03       18 阅读
  7. ios CCUIHilightedLabel.m

    2024-07-23 06:18:03       16 阅读
  8. 动态内存管理

    2024-07-23 06:18:03       11 阅读
  9. linux协议栈之FDB表

    2024-07-23 06:18:03       14 阅读