首页 > 编程语言 >C++编程题(蓝桥杯)

C++编程题(蓝桥杯)

时间:2023-03-23 16:03:33浏览次数:40  
标签:cout min int fish 编程 C++ 蓝桥 chh chs

C++编程题(蓝桥杯)_fish

 

 

C++编程题(蓝桥杯)_i++_02

 

 

运行结果

C++编程题(蓝桥杯)_i++_03

 

 

#include <iostream>
using namespace std;
void jingsai1()
{
    //chh:水深; chs:最初水下深度; 
    int chh=0,chs=0;
    int I_depth=0;
    cout<<"请输入水深和最初下水深度:"; 
    cin>>chh>>chs;    
    cout<<chh<<","<<chs<<endl;    
    I_depth=chs;
    //u:上浮1米;d:下沉一米 
    cout<<"请输入指令集:";
    char orderGroup[100]    ;
    cin>>orderGroup;
    cout<<orderGroup<<endl;
    for (int i=0;i<20;i++)
    {
        if (orderGroup[i]=='\0')
        {
            break;
        }
        char ch=orderGroup[i];
        switch (ch)
        {
            case 'u':                
                if (I_depth>0)
                {
                    I_depth--;
                }    
                cout<<"上浮1米,当前水深"<<I_depth<<endl;            
                break;
            case 'd':                
                if (I_depth<chh)
                {
                    I_depth++;
                }    
                cout<<"下沉1米,当前水深"<<I_depth<<endl;            
                break; 
            default:
                cout<<"无效的命令"<<endl;
                break;
        }
    }
    cout<<"当前水深:"<<I_depth<<endl;
}

C++编程题(蓝桥杯)_i++_04

 

 

C++编程题(蓝桥杯)_ci_05

 

 

C++编程题(蓝桥杯)_fish_06

 

 

运行结果

C++编程题(蓝桥杯)_i++_07

 

 

void jingsai2()
{
    int n=0;//站点数 
    cin>>n;
    int fish[n][2];//第一列保持鱼的价格,第二列保存运费
    int min_sum=0; //存储一路下来花费的最小费用
    //
    //int min=100000;//当前 站点最小花费         
    int min=INT_MAX;
    for (int i=0;i<n;i++) 
    {
        for (int j=0;j<2;j++)
        {
            cin>>fish[i][j];
        }        
    }
    for (int i=0;i<n;i++) 
    {
        for (int j=0;j<2;j++)
        {
            cout<<fish[i][j]<<" ";
        }        
        cout<<endl; 
    }
    
    for (int i=0;i<n;i++)
    {
        if (fish[i][0]<min)
        {
            min=fish[i][0];    //本站的最小花费 
        }
        min_sum=min_sum+min;
        min=min+fish[i][1]; //站的最小花费+本站保存的费用 
        cout<<i<<":"<<min_sum<<endl;
    }
    cout<<min_sum;        
    
}

 



标签:cout,min,int,fish,编程,C++,蓝桥,chh,chs
From: https://blog.51cto.com/u_1017534/6145614

相关文章