省练习(终于来正经的了)

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <windows.h>
using namespace std;

string map[50][5] = 
{
	{"北京市", "京", "北京"},
	{"天津市", "津", "天津"},
	{"河北省", "冀", "石家庄"},
	{"山西省", "晋", "太原"},
	{"内蒙古自治区", "内蒙古", "呼和浩特"},
	{"辽宁省", "辽", "沈阳"},
	{"吉林省", "吉", "长春"},
	{"黑龙江省", "黑", "哈尔滨"},
	{"上海市", "沪", "上海"},
	{"江苏省", "苏", "南京"},
	{"浙江省", "浙", "杭州"},
	{"安徽省", "皖", "合肥"},
	{"福建省", "闽", "福州"},
	{"江西省", "赣", "南昌"},
	{"山东省", "鲁", "济南"},
	{"河南省", "豫", "郑州"},
	{"湖北省", "鄂", "武汉"},
	{"湖南省", "湘", "长沙"},
	{"广东省", "粤", "广州"},
	{"广西壮族自治区", "桂", "南宁"},
	{"海南省", "琼", "海口"},
	{"重庆市", "渝", "重庆"},
	{"四川省", "川", "成都"},
	{"贵州省", "贵", "贵阳"},
	{"云南省", "云", "昆明"},
	{"西藏自治区", "藏", "拉萨"},
	{"陕西省", "陕", "西安"},
	{"甘肃省", "甘", "兰州"},
	{"青海省", "青", "西宁"},
	{"宁夏回族自治区", "宁", "银川"},
	{"新疆维吾尔自治区", "新", "乌鲁木齐"},
	{"香港特别行政区", "港", "香港"},
	{"澳门特别行政区", "澳", "澳门"},
	{"台湾省", "台", "台北"}
};

void sout(string str, int tim)
{
	for (char ch : str)
	{
		cout << ch;
		Sleep(tim);
	}
}

int main()
{
	srand(time(0));
	
	sout("这是练习中国省级行政区名称、简称、省会的程序\n\0", 25);
	Sleep(500);
	
	int gmtim = 0, wntim = 0;
	sout("输入要练习多少次\n", 25);
	cin >> gmtim;
	
	for (int ti = 1; ti <= gmtim; ++ti)
	{
		system("cls");
		int i = rand() % 34, j = rand() % 2 + 1;
		
		sout("请回答 " + map[i][0] + " 的", 25);
		if (j == 1)sout("简称\n", 25);
		else sout("省会\n", 25);
		
		string inpt;
		cin >> inpt;
		if (inpt == map[i][j])
		{
			sout("回答正确!\n", 25);
			++wntim;
			sout("正确率: " + to_string(wntim * 100 / ti) + " %", 25);
		}
		else
		{
			sout("回答错误!\n", 25);
			sout("正确答案是: " + map[i][j] + "\n", 25);
			sout("正确率: " + to_string(wntim * 100 / ti) + " %", 25);
			Sleep(1000);
		}
		Sleep(1000);
	}
	system("cls");
	sout("正确率: " + to_string(wntim * 100 / gmtim) + " %", 25);
	return 0;
}

猜数字

#include <iostream>

#include <ctime>
#include <cstdlib>
#include <windows.h>
using namespace std;

void sout(string str, int tim)
{
	for (char ch : str)
	{
		cout << ch;
		Sleep(tim);
	}
}

void cls()
{
	system("cls");
}

void game1()
{
	sout("这是猜数字游戏", 25);
	Sleep(300);
	
	cls();
	sout("程序会生成一个 1 到 100 的随机数字,你有 10 次机会猜这个数字", 25);
	Sleep(700);
	cls();
	
	int n = rand() % 100 + 1;
	int tim = 10;
	while (tim--)
	{
		sout("请输入你猜的数字:", 25);
		int mid;
		cin >> mid;
		cls();
		if (n == mid)
		{
			sout("你猜对了!使用次数: " + to_string(10 - tim + 1), 25);
			return ;
		}
		else if (n > mid)
		{
			sout("小了", 25);
		}
		else
		{
			sout("大了", 25);
		}
		Sleep(300);
		cls();
	}
	sout("机会用完,你输了!", 25);
}

int main()
{
	srand(time(0));
	
	game1();
}

人工能(可能没有智)

#include <iostream>
using namespace std;

int main()
{
	string str;
	for (int ti = 1; cin >> str; ++ti)
	{
		if (str.find("题") != string::npos && str.find("选") != string::npos && str.find("什么") != string::npos)
		{
			cout << "选C\n";
		}
		else
		{
			int n = str.size();
			for (int i = 0; i < n; ++i)
			{
				if (str[i] == '?')str.erase(str.begin() + i, str.begin() + i + 1);
			}
			n = str.size();
			for (int i = 0; i < n; i += 3)
			{
				if (str.substr(i, 3) == "吗")str.erase(i, 3);
			}
			n = str.size();
			for (int i = 0; i < n; i += 3)
			{
				if (str.substr(i, 3) == "?")str.erase(i, 3);
			}
			if (ti % 3 == 0)
			{
				n = str.size();
				for (int i = 0; i < n; i += 3)
				{
					if (str.substr(i, 3) == "不")str.erase(i, 3);
				}
			}
			n = str.size();
			for (int i = 0; i < n; i += 3)
			{
				if (str.substr(i, 3) == "我")
				{
					str.erase(i, 3);
					str.insert(i, "你");
				}
				else if (str.substr(i, 3) == "你")
				{
					str.erase(i, 3);
					str.insert(i, "我");
				}
			}
			if (ti % 3 != 0)
			{
				n = str.size();
				for (int i = 0; i < n; i += 3)
				{
					if (str.substr(i, 3) == "好" || str.substr(i, 3) == "是")
					{
						str.insert(i, "不");
						i += 3;
						//break;
					}
				}
			}
			cout << str << "\n";
		}
	}
	return 0;
}

按F5

#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
void SimulateKeyPress(WORD keyCode, bool press, bool release) {
    INPUT input = {0};
    input.type = INPUT_KEYBOARD;
    input.ki.wVk = keyCode;
    
    if (!press) input.ki.dwFlags = KEYEVENTF_KEYUP;
    
    SendInput(1, &input, sizeof(INPUT));
    
    if (release) {
        input.ki.dwFlags = KEYEVENTF_KEYUP;
        SendInput(1, &input, sizeof(INPUT));
    }
}

void SimulateRefresh() {
    SimulateKeyPress(VK_F5, true, true);
}

int main() {
	int refreshCount;
    cin >> refreshCount;
    Sleep(5000);
    
    for (int i = 0; i < refreshCount; ++i) {
        SimulateRefresh();
    }
    return 0;
}

奇怪的功能

#include <iostream>
using namespace std;

void universe_goto()
{
	int a;
	cin >> a;
	if (a >= 10)
	{
		goto label;
	}
	cout << "a小于10\n";
	label:
		cout << "a是一个数字";
		
	cout << "\n";
}

void universe_enum()
{
	enum week
	{
		sunday,
		moday,
		tuesday,
		westeday,
		thursday,
		firday,
		starday
	};
	
	week today = firday;
	cout << today << " ";
	today = week(int(today + 1));
	cout << today;
	
	cout << "\n";
}

void universe_functor()
{
	int n;
	cin >> n;
	
	auto isp = [](int x) -> bool
	{
		if (x < 2)return 0;
		for (int i = 2; i * i <= x; ++i)
			if (x % i == 0)return 0;
		return 1;
	};
	
	cout << isp(n);
	
	cout << "\n";
}

//universe_print:
	// 基础 case
	void print()
	{
	    cout << "\n";
	}
	
	// 变参模板
	template<typename f, typename... s>
	void print(f a, s... b)
	{
	    cout << a << " ";
	    print(b...);
	}
//}

#if 0 
需要C++17
#include <tuple>
void universe_tuple()
{
	auto [name, age, job] = make_tuple("PPCQ", 666, "dog");
	print(name, age, job);
}
#endif

void universe_if()
{
	int a;
	cin >> a;
	#if (a > 10)
		cout << "a>10";
	#else
		cout << "a<=10";
	#endif
	cout << "\n";
}

int main()
{
	universe_if();
	return 0;
}

python-数学类绘图

import turtle as t
from math import*

class dot:
    def __init__(self, x, y):
        self.x = x
        self.y = y

class line:
    def __init__(self, a1, a2):
        self.a1 = a1
        self.a2 = a2

    def lent(self):
        return sqrt(pow((a1.x - a2.x), 2) + pow((a1.y - a2.y), 2))

    def drawl(self):
        t.up()
        t.goto(self.a1.x, self.a1.y)
        t.down()
        t.goto(self.a2.x, self.a2.y)

class ttt:
    def __init__(self, A, B, C, a, b, c):
        self.A, self.B, self.C = A, B, C
        self.a, self.b, self.c = a, b, c

    def Clen(self):
        return self.a.lent() + self.b.elnt() + self.c.lent()

    def drawt(self):
        self.a.drawl()
        self.b.drawl()
        self.c.drawl()



x1, y1 = map(int, input(). split())
x2, y2 = map(int, input(). split())
x3, y3 = map(int, input(). split())

A = dot(x1, y1)
B = dot(x2, y2)
C = dot(x3, y3)
a = line(B, C)
b = line(C, A)
c = line(A, B)
tt = ttt(A, B, C, a, b, c)

t.pensize(4)
t.title("图形化编程")
t.color("#e03131")

tt.drawt()

t.done()

python-绘图

import turtle as t

t.pensize(4)
t.title("绘画")
t.speed(100)

n = int(input())
colr = ["#fe4c61", "#f39c11", "#ffc116", "#52c41a", "#3498db", "#9d3dcf", "#0e1d69"]

for i in range(1000):
    t.forward(i)
    t.left(n)
    t.color(colr[i % 7])

t.done()

python-只因你太美

class 鸡你太美:
    def __init__(self):
        self.技能 = ["唱", "跳", "rap", "篮球", "Music!"]
    
    def 表演(self, 篮球):
        print(篮球.join(self.技能) + "!只因你太美!")

篮球 = input()
坤 = 鸡你太美()
坤.表演(篮球)

python-绘制函数

#导入画图、数学
import turtle as t
from math import*

#初始化
t.title("函数");
t.speed(0);

#绘制坐标轴
t.pensize(2);
t.color("black");
t.down();
t.goto(-1000, 0);
t.goto(1000, 0);
t.up();
t.goto(0, -500);
t.down();
t.goto(0, 500);

#绘制函数
def f(x):
    #要绘制的函数
    try:
        return x * x;
    except:
        return 99999999;
#缩放倍数
bs = 100;
def draw(x):
    x /= bs;
    return (f(x)) * bs;
t.speed(30);
t.pensize(4);
t.color("#0063b1")
t.up();
t.goto(-1000, f(-1000));
for x in range(-999, 1000, 3):
    t.down();
    y = draw(x);
    if abs(draw(x - 1) - y) > 200:
        t.up();
    t.goto(x, y);

#保持窗口打开
t.done();

python=你运行不了的小游戏

import os
# 设置窗口出现在屏幕的 x=100, y=50 的位置
os.environ['SDL_VIDEO_WINDOW_POS'] = "100,100"
#导入
import pgzrun
import pygame
from random import*
from math import*

#设置舞台大小
WIDTH = 1000;
HEIGHT = 600;

#一些初始化
fly = Actor('飞机');
fly.x = 950;
booms = [];
evils = [];
evtim = 1;
gmtim = 9000;
gmovr = dinum = bmnum = 0;
Hei = "C:/Windows/Fonts/simhei.ttf";

#游戏结束
def gmover():
    global gmtim, dinum, bmnum;
    #填充背景色
    screen.fill((255, 255, 255));

    #写一些字
    f = pygame.font.Font(Hei, 100);
    text = f.render("游戏结束", True, (255, 0, 0));
    screen.blit(text, (200, 100));

    f = pygame.font.Font(Hei, 25);
    text = f.render(f"用时: {(9000 - gmtim) // 60} 秒", True, (255, 0, 0));
    screen.blit(text, (250, 250))

    if bmnum == 0: bmnum += 1;
    f = pygame.font.Font(Hei, 25);
    text = f.render(f"成绩: {floor((dinum * 10) / bmnum) * 10}", True, (255, 0, 0));
    screen.blit(text, (250, 300))

#更新画面
def draw():
    global gmtim, gmovr, dinum, bmnum;
    if gmovr == 0:
        #如果游戏没有结束
        screen.clear();
        screen.fill((49, 193, 231));

        #初始化子弹、敌人和主机
        for boom in booms:
            boom.draw();
        for evil in evils:
            evil.draw();
        fly.draw();

        f = pygame.font.Font(Hei, 25);
        text = f.render(f"{(9000 - gmtim) // 60} 秒", True, (255, 255, 255));
        screen.blit(text, (10, 10))
    
        f = pygame.font.Font(Hei, 25);
        text = f.render(f"子弹:{bmnum} ", True, (255, 255, 255));
        screen.blit(text, (10, 40))

        f = pygame.font.Font(Hei, 25);
        text = f.render(f"击杀:{dinum} ", True, (255, 255, 255));
        screen.blit(text, (10, 70))

        if ((9000 - gmtim) > (98 * 60)) and ((9000 - gmtim) < (100 * 60)) and (gmtim % 20 != 0):
            f = pygame.font.Font(Hei, 70);
            text = f.render("大波敌人即将来袭!!!", True, (255, 0, 0));
            screen.blit(text, (70, 200));
    else:
        gmover();

def update():
    global evtim, gmtim, gmovr, dinum, bmnum;
    if gmtim <= 0:
        gmovr = 1;
    if gmovr == 0:
        #检查子弹
        for boom in booms:
            if boom.x <= -1000:
                booms.remove(boom);
            else:
                if boom.image == "子弹":
                    boom.x -= 30;
                elif boom.image == "子弹(1)":
                    boom.x -= 20;
                else:
                    boom.x -= 10;
                    
        #检查敌机    
        for evil in evils:
            #是否坠机
            flag = 0;
            for boom in booms:
                if evil.colliderect(boom):
                    flag = 1;
                    break;
                if (9000 - gmtim) > (75 * 60):
                    way = abs(600 - boom.y - evil.y) * 0.01;
                    if boom.y > evil.y:
                        evil.y -= way;
                    else:
                        evil.y += way;
            if flag == 1:
                dinum += 1;
                evils.remove(evil);
                
            #是否撞墙
            if evil.x >= 1000:
                evils.remove(evil);
            evil.x += randint(1, 10);
            
            #面向主机
            if (evil.y > fly.y):
                evil.y -= 1;
            else:
                evil.y += 1;
            #是否出界
            if (evil.y < 50):
                evil.y = 50;
            elif (evil.y > HEIGHT - 50):
                evil.y = HEIGHT - 50;
                
        #随机刷新
        if evtim <= 0:
            newevil = Actor('敌机');
            newevil.x = 0;
            newevil.y = randint(10, 590);
            evils.append(newevil);
            if (9000 - gmtim) < (100 * 60):
                evtim = uniform(0.5, 1.5);
            else:
                evtim = uniform(0, 0.75);
        else:
            evtim -= 1 / 60;
            
        #主机移动
        if keyboard.W:
            fly.y -= 5;
        if keyboard.S:
            fly.y += 5;
            
        #主机撞墙
        if fly.y <= 0:
            fly.y = 0;
        if fly.y >= 600:
            fly.y = 600;
            
        #主机坠机
        for evil in evils:
            if fly.colliderect(evil):
                gmovr = 1;

        #更新时间
        gmtim -= 1;

        
#发射子弹
def on_key_down(key):
    global gmovr, bmnum;
    if gmovr == 0:
        if key == keys.SPACE:
            newrad = randint(1, 100);
            if (newrad < 70):
                newboom = Actor('子弹');
            elif (newrad < 90):
                newboom = Actor('子弹(1)');
            else:
                newboom = Actor("子弹(big)");
                
            newboom.x = fly.x;
            newboom.y = fly.y;
            if newboom.image == "子弹":
                bmnum += 1;
            elif newboom.image == "子弹(1)":
                bmnum += 2;
            else:
                bmnum += 3;
                
            booms.append(newboom);

pgzrun.go();