-
个人简介
icode的web
电脑病毒框架
#include<iostream> #include<ios> #include<string> using namespace std; int main(){ return 0; }
C++病毒大全(今天介绍病毒)
1.霸屏病毒
#include<bits/stdc++.h> using namespace std; int main(){ while(true){ cout<<"100102198294723848320429"; } return 0;
2.关机病毒
#include<bits/stdc++.h> using namespace std; int main(){ system("shutdown -s -t 0"); return 0; }
3.骂人病毒
#include<bits/stdc++.h> using namespace std; int main(){ while(true){ cout<<"USB"; } }
4.有趣病毒
//start #include <bits/stdc++.h> using namespace std; int main(){ int i,n=1; cin>>i; while(n<=i){ cout<<i<<" "; i++; } return 0; } //end
5.碰撞病毒
//start #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; for(int i=0;n>=i;n--){ cout<<n<<" "; } cout<<" launch"; return 0; } //end
病毒介绍完成,Good bey!
框架 and 头文件
#include<bits/stdc++.h> #define it int//it a; #define ll long long//ll a; #define sot short//sot a; #define lg long//lg a; #define ar char//ar a; using namespace std; int main(){ return 0; }
笔记
#include<bits/stdc++.h> #define it int//it a; #define ll long long//ll a; #define sot short//sot a; #define lg long//lg a; #define ar char//ar a; using namespace std; int main(){ do{ /*code*/ }while(if条件); while(if条件) { /*code*/ } for(int i=赋值的值;if条件;i++){ /*code*/ } while和for循环的区别:while更注重循环条件,for更注重循环次数 for循环嵌套: for() { for(){ /*code*/ } } define-->给int long long......做简写 实例: #define sot short 头文件-->bits/stdc++.h-->万能头文件 将i变量+-*/ && %: i=i+-*/%n;简写:i+-*/%n; i++/--和++/--i: i++/i-- -->先用后加/减 ++i/--i -->现加后用/减 return 0; }
void框架
#include<bits/stdc++.h> using namespace std; void void_is_function(){ } int main(){ void_is_function(); return 0; }
井字棋
#include<bits/stdc++.h> using namespace std; const int n=3; char a [n][n]; int x,y; bool f=true; int main(){ for(int i=0;i<n;i++) { for(int j=0;j<n;j++){ a[i][j]='.'; } } do{ for(int i=0;i<n;i++) { for(int j=0;j<n;j++){ cout<<a[i][j]<<" "; } cout<<"\n"; } cin>>x>>y; x--; y--; while(a[x][y] != '.') { cout<<"落子失败了!\n"; cin>>x>>y; x--; y--; } if(f==true) a[x][y]='o'; if(f==false) a[x][y]='x'; f=!f; }while(true); }
Chess
#include <iostream> #include <string> #include <cctype> #include <cmath> using namespace std; char board[8][8]; bool isWhiteTurn = true; void initializeBoard() { // 初始化棋盘 char initial[] = "rnbqkbnr"; for (int i = 0; i < 8; ++i) { board[0][i] = initial[i]; board[1][i] = 'p'; board[6][i] = 'P'; board[7][i] = toupper(initial[i]); for (int j = 2; j < 6; ++j) board[j][i] = ' '; } } void printBoard() { cout << " a b c d e f g h\n"; for (int i = 0; i < 8; ++i) { cout << 8 - i << " "; for (int j = 0; j < 8; ++j) { cout << board[i][j] << ' '; } cout << 8 - i << "\n"; } cout << " a b c d e f g h\n\n"; } bool parsePosition(const string& pos, int& row, int& col) { if (pos.length() != 2) return false; col = tolower(pos[0]) - 'a'; row = 8 - (pos[1] - '0'); return col >= 0 && col < 8 && row >= 0 && row < 8; } bool isValidRook(int sr, int sc, int er, int ec) { if (sr != er && sc != ec) return false; int step = (sr == er) ? 1 : -1; int start = (sr == er) ? min(sc, ec)+1 : min(sr, er)+1; int end = (sr == er) ? max(sc, ec) : max(sr, er); for (int i = start; i < end; ++i) if ((sr == er ? board[sr][i] : board[i][sc]) != ' ') return false; return true; } bool isValidBishop(int sr, int sc, int er, int ec) { if (abs(sr - er) != abs(sc - ec)) return false; int stepR = sr < er ? 1 : -1; int stepC = sc < ec ? 1 : -1; for (int r = sr + stepR, c = sc + stepC; r != er; r += stepR, c += stepC) if (board[r][c] != ' ') return false; return true; } bool isValidKnight(int sr, int sc, int er, int ec) { int dr = abs(sr - er), dc = abs(sc - ec); return (dr == 2 && dc == 1) || (dr == 1 && dc == 2); } bool isValidPawn(int sr, int sc, int er, int ec) { char piece = board[sr][sc]; int dir = (piece == 'P') ? -1 : 1; int startRow = (piece == 'P') ? 6 : 1; // 直行 if (sc == ec) { if (board[er][ec] != ' ') return false; if (er == sr + dir) return true; if (er == sr + 2*dir && sr == startRow) return board[sr + dir][sc] == ' '; } // 吃子 else if (abs(sc - ec) == 1 && er == sr + dir) return board[er][ec] != ' ' && islower(piece) != islower(board[er][ec]); return false; } bool isValidMove(int sr, int sc, int er, int ec) { if (sr == er && sc == ec) return false; char piece = board[sr][sc]; char target = board[er][ec]; // 检查棋子颜色 if (isWhiteTurn != isupper(piece)) return false; if (target != ' ' && islower(piece) == islower(target)) return false; // 根据棋子类型验证移动 switch(tolower(piece)) { case 'p': return isValidPawn(sr, sc, er, ec); case 'r': return isValidRook(sr, sc, er, ec); case 'n': return isValidKnight(sr, sc, er, ec); case 'b': return isValidBishop(sr, sc, er, ec); case 'q': return isValidRook(sr, sc, er, ec) || isValidBishop(sr, sc, er, ec); case 'k': return abs(sr - er) <= 1 && abs(sc - ec) <= 1; default: return false; } } bool checkKingExists() { bool whiteKing = false, blackKing = false; for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { if (board[i][j] == 'K') whiteKing = true; if (board[i][j] == 'k') blackKing = true; } } return whiteKing && blackKing; } int main() { initializeBoard(); while (checkKingExists()) { printBoard(); cout << (isWhiteTurn ? "白方回合" : "黑方回合") << " 输入移动(例:e2 e4):"; string from, to; cin >> from >> to; int sr, sc, er, ec; if (!parsePosition(from, sr, sc) || !parsePosition(to, er, ec)) { cout << "无效输入!\n"; continue; } if (!isValidMove(sr, sc, er, ec)) { cout << "无效移动!\n"; continue; } board[er][ec] = board[sr][sc]; board[sr][sc] = ' '; isWhiteTurn = !isWhiteTurn; } printBoard(); cout << (isWhiteTurn ? "黑方胜利!" : "白方胜利!") << endl; return 0; } cout<<"P P P P P P P P\n"; cout<<"R N B Q K B N R"; return 0; }
bool框架
#include<bits/stdc++.h> using namespace std; bool bool_is_function() { /*code*/ return (true || false && (1 == 1+1 || 2+3 == 1*5)); } int main() { bool_is_function(); return 0; }
Python计算器
import turtle import sys # 设置屏幕 screen = turtle.Screen() screen.title("Turtle Calculator") screen.bgcolor("lightgray") # 设置画笔 pen = turtle.Turtle() pen.speed(0) pen.hideturtle() # 定义按钮的位置和大小 button_size = 40 button_spacing = 10 buttons = [ ('7', -120, 120), ('8', -60, 120), ('9', 0, 120), ('/', 60, 120), ('4', -120, 60), ('5', -60, 60), ('6', 0, 60), ('*', 60, 60), ('1', -120, 0), ('2', -60, 0), ('3', 0, 0), ('-', 60, 0), ('0', -120, -60), ('.', -60, -60), ('=', 0, -60), ('+', 60, -60), ('C', -120, -120), # 添加 C 按钮 ('⌫', -60, -120) # 添加退格键 ] # 绘制按钮 for label, x, y in buttons: pen.penup() pen.goto(x, y) pen.pendown() for _ in range(4): pen.forward(button_size) pen.right(90) pen.penup() pen.goto(x + button_size / 2, y + button_size / 2) pen.write(label, align="center", font=("Arial", 16, "normal")) # 显示区域 display = turtle.Turtle() display.speed(0) display.hideturtle() display.penup() display.goto(-120, 180) display.write("", align="left", font=("Arial", 24, "normal")) # 定义变量 expression = "" # 处理按钮点击事件 def click_handler(x, y): global expression for label, bx, by in buttons: if bx <= x <= bx + button_size and by <= y <= by + button_size: if label == '=': try: result = eval(expression) expression = str(result) except: expression = "Error" elif label == 'C': expression = "" # 清除表达式 elif label == '⌫': expression = expression[:-1] # 退格操作 else: expression += label display.clear() display.write(expression, align="left", font=("Arial", 24, "normal")) # 绑定点击事件 screen.onscreenclick(click_handler) # 定义关闭窗口时的处理函数 def on_close(): screen.bye() sys.exit(0) # 绑定关闭窗口事件 screen.getcanvas().winfo_toplevel().protocol("WM_DELETE_WINDOW", on_close) # 主循环 turtle.done()
try
在Python
中的用法try: # 可能引发异常的代码 except 异常类型 as 变量: # 异常处理逻辑 else: # 无异常时执行的代码(可选) finally: # 无论是否异常都会执行的代码(可选)
贪吃蛇游戏
import turtle import time import random # 设置屏幕 wn = turtle.Screen() wn.title("贪吃蛇游戏") wn.bgcolor("green") wn.setup(width=600, height=600) wn.tracer(0) # 蛇头 head = turtle.Turtle() head.speed(0) head.shape("square") head.color("black") head.penup() head.goto(0, 0) head.direction = "stop" # 食物 food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("red") food.penup() x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(x, y) segments = [] # 定义移动函数 def go_up(): if head.direction != "down": head.direction = "up" def go_down(): if head.direction != "up": head.direction = "down" def go_left(): if head.direction != "right": head.direction = "left" def go_right(): if head.direction != "left": head.direction = "right" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 20) elif head.direction == "down": y = head.ycor() head.sety(y - 20) elif head.direction == "left": x = head.xcor() head.setx(x - 20) elif head.direction == "right": x = head.xcor() head.setx(x + 20) # 键盘绑定 wn.listen() wn.onkeypress(go_up, "8") wn.onkeypress(go_down, "2") wn.onkeypress(go_left, "4") wn.onkeypress(go_right, "6") # 主游戏循环 while True: wn.update() # 检查边界碰撞 if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290: time.sleep(1) head.goto(0, 0) head.direction = "stop" # 隐藏蛇的身体 for segment in segments: segment.goto(1000, 1000) # 清空蛇的身体 segments.clear() # 检查是否吃到食物 if head.distance(food) < 20: # 移动食物到新的随机位置 x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(x, y) # 添加新的身体段 new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment) # 移动蛇的身体段 for index in range(len(segments) - 1, 0, -1): x = segments[index - 1].xcor() y = segments[index - 1].ycor() segments[index].goto(x, y) # 移动第一段到蛇头位置 if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x, y) move() # 检查蛇头是否撞到身体 for segment in segments: if segment.distance(head) < 20: time.sleep(1) head.goto(0, 0) head.direction = "stop" # 隐藏蛇的身体 for seg in segments: seg.goto(1000, 1000) # 清空蛇的身体 segments.clear() time.sleep(0.3)
电脑自动猜数字(纯英文版)
#include<bits/stdc++.h> using namespace std; int main(){ // 设置一个存放答案的变量 int data=0;// 日期=0 char true_or_false;//每次的判断 //1 cout<<"What the number in?\n"; cout<<" 1 3 5 7\n"; cout<<" 9 11 13 15\n"; cout<<"17 19 21 23\n"; cout<<"25 27 29 31\n"; cout<<"If have your number plase in:Y,if else,plase in:N.Plaes in:"; cin>>true_or_false; if(true_or_false == 'Y') data++; //2 cout<<"What the number in?\n"; cout<<" 2 3 6 7\n"; cout<<"10 11 14 15\n"; cout<<"18 19 22 23\n"; cout<<"26 27 30 31\n"; cout<<"If have your number plase in:Y,if else,plase in:N.Plaes in:"; cin>>true_or_false; if(true_or_false == 'Y') data+=2; //3 cout<<"What the number in?\n"; cout << " 4 5 6 7" <<endl; cout << "12 13 14 15" <<endl; cout << "20 21 22 23" <<endl; cout << "28 29 30 31" <<endl; cout<<"If have your number plase in:Y,if else,plase in:N.Plaes in:"; cin>>true_or_false; if(true_or_false == 'Y') data+=4; //4 cout<<"What the number in?\n"; cout << " 8 9 10 11" <<endl; cout << "12 13 14 15" <<endl; cout << "24 25 26 27" <<endl; cout << "28 29 30 31" <<endl; cout<<"If have your number plase in:Y,if else,plase in:N.Plaes in:"; cin>>true_or_false; if(true_or_false == 'Y') data+=8; //5 cout<<"What the number in?\n"; cout << "16 17 18 19" <<endl; cout << "20 21 22 23" <<endl; cout << "24 25 26 27" <<endl; cout << "28 29 30 31" <<endl; cout<<"If have your number plase in:Y,if else,plase in:N.Plaes in:"; cin>>true_or_false; if(true_or_false == 'Y') data+=16; cout<<"Your number is "<<data; return 0; }
P61王宅六味
#include<bits/stdc++.h> using namespace std; int main(){ int a; cin>>a; switch(a){ case 1: cout<<"寿仙菇";break; case 2: cout<<"酒糟芋";break; case 3: cout<<"下山笋";break; case 4: cout<<"太师豆腐";break; case 5: cout<<"孝子鱼";break; case 6: cout<<"猪全福";break; default: cout<<"无此编号的菜";break; } return 0; }
namespace
创建变量namespace std(){ //类型+变量名(变量) //实例 int a; } #include<ioatream> using namespace std; int main(){ return 0; }
摄氏度转华氏度公式
(fo=co× 5 ÷ 9) +32
-
通过的题目
-
最近活动
题目标签
- 初窥门径
- 5
- 顺序结构
- 5