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