import turtle as t
screen = t.Screen()
screen.title("旗帜")
screen.bgcolor('white')
screen.setup(800, 600)
screen.tracer()
class PartyFlag(object):
#初始化
def __init__(self , x , y ,extend):
self.x = x
self.y = y
self.extend = extend
self.frame = t.Turtle()
self.sickle = t.Turtle()
self.ax = t.Turtle()
#旗面
def drawFrame(self):
self.ax.speed(10)
self.frame.up()
self.frame.goto(self.x, self.y)
self.frame.pencolor("red")
self.frame.shapesize(2)
self.frame.speed(100)
self.frame.fillcolor("red")
self.frame.begin_fill()
self.frame.down()
self.frame.forward(300*self.extend)
self.frame.right(90)
self.frame.forward(200*self.extend)
self.frame.right(90)
self.frame.forward(300*self.extend)
self.frame.right(90)
self.frame.forward(200*self.extend)
self.frame.end_fill()
self.frame.hideturtle()
# 斧头
def drawAx(self):
self.ax.speed(10)
aX = self.frame.xcor() + 25*self.extend
aY = self.frame.ycor() - 45*self.extend
self.ax.up()
self.ax.goto(aX, aY)
self.ax.pencolor("yellow")
self.ax.pensize(2)
self.ax.speed(100)
self.ax.down()
self.ax.left(45)
self.ax.fillcolor("yellow")
self.ax.begin_fill()
self.ax.forward(30 * self.extend)
self.ax.right(90)
self.ax.circle(10 * self.extend, 90)
self.ax.right(90)
self.ax.forward(10 * self.extend)
self.ax.right(90)
self.ax.forward(15 * self.extend)
self.ax.left(90)
self.ax.forward(70 * self.extend)
self.ax.right(90)
self.ax.forward(15 * self.extend)
self.ax.right(90)
self.ax.forward(70 * self.extend)
self.ax.left(90)
self.ax.forward(10 * self.extend)
self.ax.right(90)
self.ax.forward(20*self.extend)
self.ax.end_fill()
self.ax.hideturtle()
#镰刀
def drawSicikle(self):
self.ax.speed(10)
sX = self.frame.xcor() + 30 *self.extend
sY = self.frame.ycor() - 69 *self.extend
self.sickle.up()
self.sickle.goto(sX, sY)
self.sickle.pencolor("yellow")
self.sickle.pensize(2)
self.sickle.speed(100)
self.sickle.fillcolor("yellow")
self.sickle.begin_fill()
self.sickle.right(45)
self.sickle.down()
self.sickle.circle(40 * self.extend, 90)
self.sickle.left(25)
self.sickle.circle(45 * self.extend, 90)
self.sickle.right(160)
self.sickle.circle(-45 * self.extend, 130)
self.sickle.right(10)
self.sickle.circle(-48 * self.extend,75)
self.sickle.left(160)
self.sickle.circle(-7 * self.extend, 340)
self.sickle.left(180)
self.sickle.circle(-48 *self.extend, 15)
self.sickle.right(75)
self.sickle.forward(11 * self.extend)
self.sickle.end_fill()
self.sickle.hideturtle()
#函数入口
def draw(self):
self.drawFrame()
self.drawAx()
self.drawSicikle()
if __name__ == '__main__':
#x坐标,y坐标,缩放倍数
partyFlag=PartyFlag(-300,200,2)
partyFlag.draw()
screen.mainloop()
题目一回文数的判断。给定一个数,这个数顺读和逆读都是一样的。例如:121、1221是回文数,123、1231不是回文数
标准输入:
123870
标准输出:
No
#include#include#includeusing namespace std;
int main() {string str;
cin >>str;
int n = str.size();
bool flag = 1;
for(int i=0;i flag = 0;
break;
}
if (flag)
cout<< "Yes";
else cout<< "No";
return 0;
}
题目二绘制 99 乘法表。左
对齐,每个式子间隔一个空格,一行输出完了换行
标准输出:
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
#includeusing namespace std;
int main() {cout<< "1*1=1\n";
cout<< "1*2=2 2*2=4\n";
cout<< "1*3=3 2*3=6 3*3=9\n";
cout<< "1*4=4 2*4=8 3*4=12 4*4=16\n";
cout<< "1*5=5 2*5=10 3*5=15 4*5=20 5*5=25\n";
cout<< "1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36\n";
cout<< "1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49\n";
cout<< "1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64\n";
cout<< "1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81\n";
}
题目三输入两次年
月日(不分时间先后),年月日格式为xxxx-xx-xx,并用enter间隔开两次时间。最后输出两次时间的天数之差(需要考虑到闰年与平年)
标准输入:
2012-1-20
2016-3-1
标准输出:
1502
#includeusing namespace std;
int cntdays[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31 };
int isleap(int year) {if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return true;
else return false;
}
int lesser(int y1, int m1, int d1, int y2, int m2, int d2) {if (y1 != y2)
return y1< y2;
if (m1 != m2)
return m1< m2;
if (d1 != d2)
return d1< d2;
}
int getmonthdays(int y, int m) {if (m != 2)
return cntdays[m];
else return cntdays[m] + isleap(y);
}
int getdays(int y,int m,int d) {int res = 0;
for (int i = 1;i< m;i++)
res += getmonthdays(y, i);
res += d;
return res;
}
int main() {int y1, m1, d1, y2, m2, d2;
scanf("%d-%d-%d", &y1, &m1, &d1);
scanf("%d-%d-%d", &y2, &m2, &d2);
if (!lesser(y1, m1, d1, y2, m2, d2)) {swap(y1, y2);
swap(m1, m2);
swap(d1, d2);
}
int res = 0;
for (int i = y1+1;i< y2;i++) {res += 365 + isleap(i);
}
res += getdays(y2, m2, d2);
res += 365+isleap(y1) - getdays(y1, m1, d1);
if (y1 == y2)
res = getdays(y2, m2, d2) - getdays(y1, m1, d1);
cout<< res;
}
题目四数字黑洞6174:给定任一个各位数字不完全相同的4位正整数,若先把4个数字按递减排序,再按递增排序,然后用第一个数字减第二个数字,将得到一个新的数字。一直重复这样做,会停在有“数字黑洞”之称的6174,这个神奇的数字也叫Kaprekar常数。
给定任意4位正整数,请编写程序演示到达数字黑洞6174的过程。
输入描述:输入给出一个(0,10000)区间内的正整数
输出描述:若
N
N
N的4位数字全相等,则在一行内输出N-N=0000
;否则将计算的每一步在一行内输出,直到6174作为差出现为止。每行中间没有空格,每个数字按4位格式输出,见如下样例。
标准输入:
6767
标准输出:
7766-6677=1089
9810-0189=9621
9621-1269=8352
8532-2358=6174
#include#include#include
using namespace std;
int main() {int n;
cin >>n;
if (n % 1111 == 0)
printf("%d-%d=0000", n, n);
else {int dif;
do { vectorv1(4);
v1[0] = n % 10;
v1[1] = (n % 100) / 10;
v1[2] = (n % 1000) / 100;
v1[3] = n / 1000;
sort(v1.begin(), v1.end());
int num1 = v1[3] * 1000 + v1[2] * 100 + v1[1] * 10 + v1[0];
int num2 = v1[0] * 1000 + v1[1] * 100 + v1[2] * 10 + v1[3];
dif = num1 - num2;
n = dif;
printf("%04d-%04d=%04d\n", num1, num2, dif);
} while (dif != 6174);
}
}
题目五判断是否为水仙花数。水仙花数指一个三位数,它的每个位上的数字的三次幂之和等于它本身。示例:
1
3
+
5
3
+
3
3
=
153
1^3+5^3+3^3=153
13+53+33=153
标准输入
135
标准输出
不是
#includeusing namespace std;
int main() {int n;
cin >>n;
if (n == 153 || n == 370 || n == 371 || n == 407) cout<< "是";
else cout<< "不是";
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网页题目:江苏大学1024程序员节“我与算法有个约”活动题面与题解-创新互联
链接地址:http://scgulin.cn/article/hjsci.html