老规矩看下面

20 条评论

  • ```language
    
    

    #include using namespace std;

    int main(){ int n; long long sum,sumn; sum=0; cout<<"请输入n的值:"; cin>>n; for(int i=1;i<=n;i++){ sumn=1; for(int j=1;j<=5;j++){ sumn*=i; } sum+=sumn; } cout<<sum<<endl; return 0; }

    • ```language
      
      

      #include using namespace std;

      int main(){ int n; long long sum,sumn; sum=0; cout<<"请输入n的值:"; cin>>n; for(int i=1;i<=n;i++){ sumn=1; for(int j=1;j<=5;j++){ sumn*=i; } sum+=sumn; } cout<<sum<<endl; return 0; }

      • 
        

        #include using namespace std;

        int main(){ int n; long long sum,sumn; sum=0; cout<<"请输入n的值:"; cin>>n; for(int i=1;i<=n;i++){ sumn=1; for(int j=1;j<=5;j++){ sumn*=i; } sum+=sumn; } cout<<sum<<endl; return 0; }

        • ``
          

          #include using namespace std;

          int main(){ int n; long long sum,sumn; sum=0; cout<<"请输入n的值:"; cin>>n; for(int i=1;i<=n;i++){ sumn=1; for(int j=1;j<=5;j++){ sumn*=i; } sum+=sumn; } cout<<sum<<endl; return 0; }

          • using namespace std;
            
            int main(){
            	int sum=0,jie=1,n;
            	cin>>n;
            	for(int i;i<=n;i++){
            		for(int j=1;j<=i;j++){
            			jie*=j;
            		}
            		sum+=jie;
            		jie=1;
            	}
            	cout<<sum;
            	return 0;
            }
            
            
            
            • ``
              

              #include using namespace std;

              int main(){ int sum=0,jie=1,n; cin>>n; for(int i;i<=n;i++){ for(int j=1;j<=i;j++){ jie*=j; } sum+=jie; jie=1; } cout<<sum; return 0; }

              • ``
                

                #include using namespace std;

                int main(){ int sum=0,jie=1,n; cin>>n; for(int i;i<=n;i++){ for(int j=1;j<=i;j++){ jie*=j; } sum+=jie; jie=1; } cout<<sum; return 0; }

                • ````language`

                  #include <iostream>
                  using namespace std;
                  
                  int main(){
                  	for(int ji=1;ji<=34;ji++){
                  		for(int tu=1;tu<=23;tu++){
                  			if(ji+tu==35){
                  				if(ji*2+tu*4==94){
                  					cout<<"鸡:"<<ji<<"兔:"<<tu;
                  				}
                  			}
                  		}
                  	}
                  
                  	return 0;
                  }
                  • #include <iostream>
                    #include <cstdlib>
                    #include <ctime>
                    #include <string>
                    using namespace std;
                    
                    const int MAP_SIZE = 20;    // 地图格子总数
                    const int START_MONEY = 500;// 初始金钱
                    
                    // 地图格子类型
                    enum BlockType { EMPTY, OWNED };
                    
                    // 地图格子结构体
                    struct Block {
                        BlockType type;
                        string name;
                        int price;      // 买地价格
                        int toll;       // 过路费
                        int owner;      // 拥有者 0=无 1=玩家 2=电脑
                    };
                    
                    // 玩家结构体
                    struct Player {
                        string name;
                        int money;
                        int pos;
                    };
                    
                    // 全局变量
                    Block map[MAP_SIZE];
                    Player player, computer;
                    
                    // 初始化地图
                    void InitMap() {
                        string bNames[] = {
                            "起点","公园","商业街","学校","广场",
                            "居民楼","写字楼","超市","医院","车站",
                            "花园","酒吧","书店","影院","酒店",
                            "码头","工厂","别墅","城堡","乐园"
                        };
                    
                        for (int i = 0; i < MAP_SIZE; i++) {
                            map[i].type = EMPTY;
                            map[i].name = bNames[i];
                            map[i].price = 50 + i * 20;
                            map[i].toll = 20 + i * 10;
                            map[i].owner = 0;
                        }
                    }
                    
                    // 初始化玩家
                    void InitPlayer() {
                        cout << "===== 欢迎来到大富翁 =====" << endl;
                        cout << "请输入你的名字:";
                        cin >> player.name;
                        computer.name = "电脑";
                    
                        player.money = START_MONEY;
                        computer.money = START_MONEY;
                        player.pos = 0;
                        computer.pos = 0;
                    }
                    
                    // 掷骰子
                    int RollDice() {
                        return rand() % 6 + 1;
                    }
                    
                    // 显示当前状态
                    void ShowStatus() {
                        cout << "\n=====================================" << endl;
                        cout << player.name << "  金钱:" << player.money << "  位置:" << map[player.pos].name << endl;
                        cout << computer.name << "  金钱:" << computer.money << "  位置:" << map[computer.pos].name << endl;
                        cout << "=====================================\n";
                    }
                    
                    // 玩家移动
                    void PlayerMove(int step) {
                        player.pos = (player.pos + step) % MAP_SIZE;
                        cout << "\n你掷出了 " << step << " 点,到达:" << map[player.pos].name << endl;
                    }
                    
                    // 电脑移动
                    void ComputerMove(int step) {
                        computer.pos = (computer.pos + step) % MAP_SIZE;
                        cout << "\n电脑掷出了 " << step << " 点,到达:" << map[computer.pos].name << endl;
                    }
                    
                    // 处理玩家当前格子
                    void PlayerBlock() {
                        Block &b = map[player.pos];
                        if (b.type == EMPTY) {
                            cout << "这个地块无人占领,价格:" << b.price << endl;
                            if (player.money >= b.price) {
                                cout << "是否购买?(1=买 0=不买):";
                                int choose;
                                cin >> choose;
                                if (choose == 1) {
                                    player.money -= b.price;
                                    b.type = OWNED;
                                    b.owner = 1;
                                    cout << "购买成功!" << endl;
                                }
                            } else {
                                cout << "金钱不足,无法购买" << endl;
                            }
                        } else if (b.owner == 2) {
                            cout << "踩到电脑的地块,需交过路费:" << b.toll << endl;
                            player.money -= b.toll;
                            computer.money += b.toll;
                        }
                    }
                    
                    // 处理电脑当前格子
                    void ComputerBlock() {
                        Block &b = map[computer.pos];
                        if (b.type == EMPTY && computer.money >= b.price) {
                            cout << "电脑购买了:" << b.name << endl;
                            computer.money -= b.price;
                            b.type = OWNED;
                            b.owner = 2;
                        } else if (b.owner == 1) {
                            cout << "电脑踩到你的地块,支付过路费:" << b.toll << endl;
                            computer.money -= b.toll;
                            player.money += b.toll;
                        }
                    }
                    
                    // 判断游戏结束
                    bool GameOver() {
                        if (player.money <= 0) {
                            cout << "\n你破产了!游戏结束,电脑胜利!" << endl;
                            return true;
                        }
                        if (computer.money <= 0) {
                            cout << "\n电脑破产了!游戏结束,你胜利!" << endl;
                            return true;
                        }
                        return false;
                    }
                    
                    int main() {
                        srand((unsigned)time(NULL));
                        InitMap();
                        InitPlayer();
                    
                        while (true) {
                            ShowStatus();
                    
                            // 玩家回合
                            cout << "\n===== 你的回合 =====" << endl;
                            cout << "按回车掷骰子...";
                            cin.get();
                            cin.get();
                            int pStep = RollDice();
                            PlayerMove(pStep);
                            PlayerBlock();
                    
                            if (GameOver()) break;
                    
                            // 电脑回合
                            cout << "\n===== 电脑回合 =====" << endl;
                            cout << "电脑正在掷骰子..." << endl;
                            int cStep = RollDice();
                            ComputerMove(cStep);
                            ComputerBlock();
                    
                            if (GameOver()) break;
                        }
                    
                        return 0;
                    }
                    
                    
                    • ````language`

                      #include <bits/stdc++.h>
                      using namespace std;
                      
                      int main(){
                      	for(int i=1;i<=9;i++){
                      		for(int j=1;j<=i;j++){
                      			cout<<j<<'*'<<i<<'='<<setw(2)<<i*j<<"  ";
                      		}
                      		cout<<endl;
                      	}
                      	return 0;
                      }
                      • ````language`

                        #include <bits/stdc++.h>
                        using namespace std;
                        
                        int main(){
                        	for(int i=1;i<=9;i++){
                        		for(int j=1;j<=i;j++){
                        			cout<<j<<'*'<<i<<'='<<setw(2)<<i*j<<"  ";
                        		}
                        		cout<<endl;
                        	}
                        	return 0;
                        }
                        • #include <iostream>
                          #include <cstdlib>
                          #include <ctime>
                          #include <string>
                          using namespace std;
                          
                          const int MAP_SIZE = 20;    // 地图格子总数
                          const int START_MONEY = 1;// 初始金钱
                          
                          // 地图格子类型
                          enum BlockType { EMPTY, OWNED };
                          
                          // 地图格子结构体
                          struct Block {
                              BlockType type;
                              string name;
                              int price;      // 买地价格
                              int toll;       // 过路费
                              int owner;      // 拥有者 0=无 1=玩家 2=电脑
                          };
                          
                          // 玩家结构体
                          struct Player {
                              string name;
                              int money;
                              int pos;
                          };
                          
                          // 全局变量
                          Block map[MAP_SIZE];
                          Player player, computer;
                          
                          // 初始化地图
                          void InitMap() {
                              string bNames[] = {
                                  "起点","公园","商业街","学校","广场",
                                  "居民楼","写字楼","超市","医院","车站",
                                  "花园","酒吧","书店","影院","酒店",
                                  "码头","工厂","别墅","城堡","乐园"
                              };
                          
                              for (int i = 0; i < MAP_SIZE; i++) {
                                  map[i].type = EMPTY;
                                  map[i].name = bNames[i];
                                  map[i].price = 50 + i * 20;
                                  map[i].toll = 20 + i * 10;
                                  map[i].owner = 0;
                              }
                          }
                          
                          // 初始化玩家
                          void InitPlayer() {
                              cout << "===== 欢迎来到大富翁 =====" << endl;
                              cout << "请输入你的名字:";
                              cin >> player.name;
                              computer.name = "电脑";
                          
                              player.money = START_MONEY;
                              computer.money = START_MONEY;
                              player.pos = 0;
                              computer.pos = 0;
                          }
                          
                          // 掷骰子
                          int RollDice() {
                              return rand() % 6 + 1;
                          }
                          
                          // 显示当前状态
                          void ShowStatus() {
                              cout << "\n=====================================" << endl;
                              cout << player.name << "  金钱:" << player.money << "  位置:" << map[player.pos].name << endl;
                              cout << computer.name << "  金钱:" << computer.money << "  位置:" << map[computer.pos].name << endl;
                              cout << "=====================================\n";
                          }
                          
                          // 玩家移动
                          void PlayerMove(int step) {
                              player.pos = (player.pos + step) % MAP_SIZE;
                              cout << "\n你掷出了 " << step << " 点,到达:" << map[player.pos].name << endl;
                          }
                          
                          // 电脑移动
                          void ComputerMove(int step) {
                              computer.pos = (computer.pos + step) % MAP_SIZE;
                              cout << "\n电脑掷出了 " << step << " 点,到达:" << map[computer.pos].name << endl;
                          }
                          
                          // 处理玩家当前格子
                          void PlayerBlock() {
                              Block &b = map[player.pos];
                              if (b.type == EMPTY) {
                                  cout << "这个地块无人占领,价格:" << b.price << endl;
                                  if (player.money >= b.price) {
                                      cout << "是否购买?(1=买 0=不买):";
                                      int choose;
                                      cin >> choose;
                                      if (choose == 1) {
                                          player.money -= b.price;
                                          b.type = OWNED;
                                          b.owner = 1;
                                          cout << "购买成功!" << endl;
                                      }
                                  } else {
                                      cout << "金钱不足,无法购买" << endl;
                                  }
                              } else if (b.owner == 2) {
                                  cout << "踩到电脑的地块,需交过路费:" << b.toll << endl;
                                  player.money -= b.toll;
                                  computer.money += b.toll;
                              }
                          }
                          
                          // 处理电脑当前格子
                          void ComputerBlock() {
                              Block &b = map[computer.pos];
                              if (b.type == EMPTY && computer.money >= b.price) {
                                  cout << "电脑购买了:" << b.name << endl;
                                  computer.money -= b.price;
                                  b.type = OWNED;
                                  b.owner = 2;
                              } else if (b.owner == 1) {
                                  cout << "电脑踩到你的地块,支付过路费:" << b.toll << endl;
                                  computer.money -= b.toll;
                                  player.money += b.toll;
                              }
                          }
                          
                          // 判断游戏结束
                          bool GameOver() {
                              if (player.money <= 0) {
                                  cout << "\n你破产了!游戏结束,电脑胜利!" << endl;
                                  return true;
                              }
                              if (computer.money <= 0) {
                                  cout << "\n电脑破产了!游戏结束,你胜利!" << endl;
                                  return true;
                              }
                              return false;
                          }
                          
                          int main() {
                              srand((unsigned)time(NULL));
                              InitMap();
                              InitPlayer();
                          
                              while (true) {
                                  ShowStatus();
                          
                                  // 玩家回合
                                  cout << "\n===== 你的回合 =====" << endl;
                                  cout << "按回车掷骰子...";
                                  cin.get();
                                  cin.get();
                                  int pStep = RollDice();
                                  PlayerMove(pStep);
                                  PlayerBlock();
                          
                                  if (GameOver()) break;
                          
                                  // 电脑回合
                                  cout << "\n===== 电脑回合 =====" << endl;
                                  cout << "电脑正在掷骰子..." << endl;
                                  int cStep = RollDice();
                                  ComputerMove(cStep);
                                  ComputerBlock();
                          
                                  if (GameOver()) break;
                              }
                          
                              return 0;
                          }
                          
                          
                          • ````language`

                            #include <iostream>
                            using namespace std;
                            
                            int main(){
                            	int a;
                            	cin>>a;
                            	char c='a' ;
                            	for(int i=0;i<a;i++){
                            		for(int j=0;j<=i;j++){
                            			cout<<c++;
                            			if(c>'z') c='a';
                            		}
                            		cout<<endl;
                            	}
                            	return 0;
                            }
                            • using namespace std;
                              
                              int main(){
                              	int a;
                              	cin>>a;
                              	char c='a';
                              	for(int i=0;i<a;i++){
                              		for(int j=0;j<=i;j++){
                              			cout<<c++;
                              			if(c>'z') c='a';
                              			
                              		}
                              		
                              		cout<<endl;
                              	} 
                              
                              	return 0;
                              }
                              
                              
                              
                              
                              
                              
                              • file://大富翁

                                • using namespace std;
                                  
                                  int main(){
                                  	int n;
                                  	cin>>n;
                                  	for(int i=1;i<=n;i++){
                                  		for(int j=n;j<=n-i;j++){
                                  			cout<<" ";
                                  			
                                  		}
                                  		for(int j=1;j<=2*i-1;j++){
                                  			cout<<"*";
                                  		}
                                  		cout<<endl;
                                  	} 
                                  
                                  	return 0;
                                  }
                                  
                                  
                                  
                                  
                                  
                                  
                                  • #include <iostream>
                                    #include <cstdlib>
                                    #include <ctime>
                                    using namespace std;
                                    
                                    //玩家结构体
                                    struct Player{
                                        int id;
                                        int role;   // 0平民 1狼人 2预言家
                                        bool alive;
                                    };
                                    Player p[7];  //1~6号玩家
                                    
                                    //初始化身份:2狼+1预言家+3平民
                                    void init(){
                                        srand((unsigned)time(NULL));
                                        //全部默认平民、存活
                                        for(int i = 1; i <= 6; i++){
                                            p[i].id = i;
                                            p[i].role = 0;
                                            p[i].alive = true;
                                        }
                                    
                                        //预言家随机一名
                                        int yu = rand() % 6 + 1;
                                        p[yu].role = 2;
                                    
                                        //两只狼人,不能重复、不能是预言家
                                        int w1,w2;
                                        do{
                                            w1 = rand() % 6 + 1;
                                        }while(w1 == yu);
                                    
                                        do{
                                            w2 = rand() % 6 + 1;
                                        }while(w2 == yu || w2 == w1);
                                    
                                        p[w1].role = 1;
                                        p[w2].role = 1;
                                    }
                                    
                                    //统计存活狼人数量
                                    int wolfNum(){
                                        int cnt = 0;
                                        for(int i = 1; i <= 6; i++){
                                            if(p[i].alive && p[i].role == 1) cnt++;
                                        }
                                        return cnt;
                                    }
                                    
                                    //统计存活总人数
                                    int aliveNum(){
                                        int cnt = 0;
                                        for(int i = 1; i <= 6; i++){
                                            if(p[i].alive) cnt++;
                                        }
                                        return cnt;
                                    }
                                    
                                    int main(){
                                        init();
                                        cout << "====== 6人简易狼人杀 ======\n";
                                        cout << "身份配置:2狼人 + 1预言家 + 3平民\n";
                                        cout << "规则:狼人杀光好人获胜,好人投出全部狼人获胜\n\n";
                                    
                                        while(true){
                                            //==========天黑阶段==========
                                            cout << "-------- 天黑请闭眼 --------\n";
                                    
                                            //1.预言家查验
                                            for(int i = 1; i <= 6; i++){
                                                if(p[i].alive && p[i].role == 2){
                                                    int check;
                                                    cout << "[预言家]请查验一名玩家(1-6):";
                                                    cin >> check;
                                                    if(p[check].role == 1){
                                                        cout << "结果:该玩家是狼人!\n\n";
                                                    }else{
                                                        cout << "结果:该玩家是好人!\n\n";
                                                    }
                                                }
                                            }
                                    
                                            //2.狼人杀人
                                            int kill;
                                            cout << "[狼人]请选择杀害玩家:";
                                            cin >> kill;
                                            if(p[kill].alive){
                                                p[kill].alive = false;
                                                cout << "玩家" << kill << " 倒在了黑夜中\n\n";
                                            }else{
                                                cout << "此人已死亡,本轮无人死亡\n\n";
                                            }
                                    
                                            //判断游戏结束
                                            int wolf = wolfNum();
                                            int all = aliveNum();
                                            if(wolf == 0){
                                                cout << "=== 好人胜利!狼人全部淘汰 ===\n";
                                                break;
                                            }
                                            if(wolf >= all - wolf){
                                                cout << "=== 狼人胜利!好人被压制 ===\n";
                                                break;
                                            }
                                    
                                            //==========天亮投票==========
                                            cout << "-------- 天亮了 --------\n";
                                            int vote;
                                            cout << "请投票放逐一名玩家:";
                                            cin >> vote;
                                            if(p[vote].alive){
                                                p[vote].alive = false;
                                                cout << "玩家" << vote << " 被大家投票出局\n\n";
                                            }else{
                                                cout << "此人已死亡,投票无效\n\n";
                                            }
                                    
                                            //再次判断结束
                                            wolf = wolfNum();
                                            all = aliveNum();
                                            if(wolf == 0){
                                                cout << "=== 好人胜利!狼人全部淘汰 ===\n";
                                                break;
                                            }
                                            if(wolf >= all - wolf){
                                                cout << "=== 狼人胜利!好人被压制 ===\n";
                                                break;
                                            }
                                        }
                                    
                                        //公布全部身份
                                        cout << "\n====== 本局身份公示 ======\n";
                                        for(int i = 1; i <= 6; i++){
                                            cout << "玩家" << i << ":";
                                            if(p[i].role == 0) cout << "平民";
                                            if(p[i].role == 1) cout << "狼人";
                                            if(p[i].role == 2) cout << "预言家";
                                            if(!p[i].alive) cout << "(已死亡)";
                                            cout << endl;
                                        }
                                        return 0;
                                    }
                                    
                                    
                                    • #include <iostream>
                                      using namespace std;
                                      
                                      int main(){
                                      	for(int i=1;i<=3;i++){
                                      		for(int j=1;j<=5;j++){
                                      			cout<<'*';
                                      		}
                                      		cout<<endl;
                                      	} 
                                      
                                      	return 0;
                                      }
                                      
                                      
                                      • #include <iostream>
                                        using namespace std;
                                        
                                        int main(){
                                        	for(int i=1;i<=3;i++){
                                        		for(int j=1;j<=5;j++){
                                        			cout<<'*';
                                        		}
                                        		cout<<endl;
                                        	} 
                                        
                                        	return 0;
                                        }
                                        
                                        
                                        
                                        
                                        • 1