【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

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_千思_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值