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)區(qū)間內的正整數
輸出描述:若
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<< "不是";
}
你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網查看詳情吧