摘要: 编码技巧C++ 非零都是true 在c++环境下不等于0的数值都被认为是true 在判断一个值是否为0时以下代码是等效的,但第一种效率更高 int i = 123; if (i) cout << "i不为0"; if (i != 0) cout << "i不为0"; 不需要用到下标的计数循环可以不用 阅读全文
posted @ 2024-04-25 22:19 iamy 阅读(34) 评论(0) 推荐(0)
摘要: 编码技巧Python 交换两个数 a = 1 b = 2 a,b = b,a 获得序列倒叙副本 s = "ABC" print(s[::-1]) l = [1,2,3] print(l[::-1]) 阅读全文
posted @ 2024-04-25 22:19 iamy 阅读(8) 评论(0) 推荐(0)
摘要: 效果 代码 import random as r import matplotlib.pyplot as plt dic = {} for i in range(3, 19): dic[i] = 0 for i in range(100000): t = 0 for j in range(3): t 阅读全文
posted @ 2024-02-08 18:00 iamy 阅读(36) 评论(0) 推荐(0)
摘要: 运行效果 代码 import turtle as t import random as r c = ["pink", "green", "lightgreen", "orange", "red", "purple"] def drawStar(l): t.begin_fill() for i in 阅读全文
posted @ 2024-02-08 17:46 iamy 阅读(55) 评论(0) 推荐(0)
摘要: 运行效果 代码 import turtle as t import time as tm def DrawDial(): # 绘制表盘 ts = t.Turtle() ts.hideturtle() ts.pensize(20) ts.speed(0) ts.color("cyan","yellow 阅读全文
posted @ 2024-02-02 18:41 iamy 阅读(72) 评论(0) 推荐(0)
摘要: 快速排序的三种方法 填坑 #include <iostream> #include <ctime> using namespace std; const int SZ = 30; int a[SZ]; void qst(int L, int R) { if (L < R) { int pivot = 阅读全文
posted @ 2023-11-05 22:22 iamy 阅读(43) 评论(0) 推荐(0)
摘要: 踩过的坑size_t类型下标逆序遍历 通过下标逆序遍历以下代码是没有问题的 string s; cin >> s; for (int i = s.length() - 1; i >= 0; --i) cout << s[i]; 但是如果用无符号类型作为循环变量的类型会出现死循环的问题,因为 i>=0 阅读全文
posted @ 2023-10-03 21:24 iamy 阅读(72) 评论(0) 推荐(0)
摘要: 数组动态创建问题 C++较新版本中允许通过变量方式动态创建数组 int n; cin >> n; int a[n] = {0}; 但有些ide会提示 "表达式必须含有常量值c/c++" 问题,可用以下方式消除此问题 int n; cin >> n; int *a = new int[n]; 注意:采 阅读全文
posted @ 2023-10-03 21:09 iamy 阅读(29) 评论(0) 推荐(0)
摘要: GSEP 6级样题 亲朋数 题目描述 给定一串长度为L、由数字 0-9 组成的数字串S。容易知道,它的连续子串共有L(L+1)/2 个。如果某个子串对应的数(允许有前导零)是p的倍数,则称该子串为数字串S对于p的亲朋数。 例如,数字串S为“12342”、p为 2,则在 15 个连续子串中,亲朋数有“ 阅读全文
posted @ 2023-10-02 00:54 iamy 阅读(699) 评论(0) 推荐(0)
摘要: GSEP 6级样题 下楼梯 题目描述 顽皮的小明发现,下楼梯时每步可以走 1 个台阶、2 个台阶或 3 个台阶。现在一共有N个台阶,你能帮小明算算有多少种方案吗? 输入格式 输入一行,包含一个整数N。约定1 ≤ N ≤ 60。 输出格式 输出一行,包含一个整数C,表示方案数。 样例 #1 样例输入 阅读全文
posted @ 2023-10-01 00:45 iamy 阅读(294) 评论(0) 推荐(0)