网站开发的需要的技术人员,网络平台营销的特点,便宜建站vps,沧州手机端网络推广http://oj.acm-icpc.top/
a题#xff1a;三个数字排序
可以利用sort函数排序#xff0c;或者自己想清楚逻辑自己写#xff0c;我给出一个正确逻辑
#xff08;拓展冒泡和其他排序参考https://blog.csdn.net/hebtu666/article/details/81434236#xff09;
a,b,cinput(…http://oj.acm-icpc.top/
a题三个数字排序
可以利用sort函数排序或者自己想清楚逻辑自己写我给出一个正确逻辑
拓展冒泡和其他排序参考https://blog.csdn.net/hebtu666/article/details/81434236
a,b,cinput().split( )
a,b,cint(a),int(b),int(c)
if ab:a,bb,a
if bc:b,cc,b
if ab:a,bb,a
print(a,b,c)
b题判断三角形能否组成
很简单直接判断即可
while 1:a,b,c[int(x) for x in input().split()]if a0:breakelif abc and acb and bca:print(Great,you are genius!)else:print(oh,my god!)
c题把1到n中的所有奇数从小到大输出再把所有的偶数从小到大输出。
利用循环加上步长一次性输出。
或者两个循环不加步长判断一下再输出即可。
timeint(input())
while 1:aint(input())for i in range(1,a1,2):print(i,end )print()for j in range(2,a1,2):print(j,end )print()timetime-1if time0:break
d题已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡和兔的数目如果无解则输出“No answer”(不要引号)。
tint(input())
while t:n,minput().split()if int(m)%20:a(int(m)-int(n)*2)/2bint(n)-aif a0 and b0:print(int(b),int(a))else:print(No answer)tt-1
e题简化版找出从自然数1-6中任取3个数的所有组合。
for a in range(6,0,-1):for b in range(6,0,-1):for c in range(6,0,-1):if abc:print(str(a)str(b)str(c))
任取n个数
#includestdio.h
int a[15];
int n,r;
void dfs(int c,int x){int i;if(xr1){for(int j1;jr;j)printf(%d,a[j]);printf(\n);}for(ic;i0;i--){a[x]i;dfs(i-1,x1);}
}
int main(){while(scanf(%d%d,n,r)2){dfs(n,1);}return 0;
}f题编写一个程序实现将字符串中的所有you替换成we
利用函数
while 1:astr(input())print(a.replace(you, we))
或遍历、判断、替换。
G题
题目描述
还记得中学时候学过的杨辉三角吗具体的定义这里不再描述你可以参考以下的图形 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1
输入
输入数据包含多个测试实例每个测试实例的输入只包含一个正整数n1n30表示将要输出的杨辉三角的层数。
输出
对应于每一个输入请输出相应层数的杨辉三角每一层的整数之间用一个空格隔开每一个杨辉三角后面加一个空行。
杨辉三角就是按照定义来模拟即可。
这里给出python的一点比较神的列表操作
列表生成式知识请看我的python总结里有。
利用定义简单明了的生成每一行杨辉
for i in range(1,n):l[1][int(l[j])int(l[j1]) for j in range(len(l)-1)][1]