任意输入一个正整数N,统计1~N之间奇数的个数和偶数的个数,并输出。
一行,一个正整数N。(1≤N≤100,000)
一行,1~N之间奇数的个数和偶数的个数,用空格分开。
5
3 2
odd=0 even=0 n=int(input()) for i in range(1,n+1): if i%2 == 0: even+=1 else: odd+=1 print('{} {}'.format(odd,even))
even = 0 # 偶数 odd = 0 # 奇数 n = int(input().strip()) for i in range(1,n+1): if i % 2 == 0: even += 1 else: odd += 1 print(f"{odd} {even}") # n = int(input()) # even = int(n/2) # 偶数个数 # odd = n - even # 奇数个数 # print(f"even: {even}\nodd: {odd}")
N = int(input()) M = int((N+1)/2) O = int(N/2) if N%2==0: print(O,O) else: print(M,M-1)
n=int(input()) even=0 odd=0 for i in range(1,n+1): if i%2==0: even+=1 else: odd+=1 print('{} {}'.format(odd,even))
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题