华科大一C++程序设计基础oj编程题参考答案


因为侵犯慕课网版权而被投诉了可还行……


第五章 编程题

1

参考答案

#include <iostream>
#include <cstring>
using namespace std;
int main(){
   
    char str[80];
    int count = 0;
    cin >> str;
    for (int i = 0;i < strlen(str);i++){
   
        if (str[i] >= 'a' && str[i] <= 'z'){
   
            str[i] += 'A' - 'a';
            count++;
        }
    }
    cout << str << endl << count;
}

2

参考答案

#include <iostream>
using namespace std;
int main(){
   
    int array[10];
    for (int i = 0;i < 10;i++){
   
        cin >> array[i];
    }
    int search;
    bool thereBe = false;
    cin >> search;
    for (int i = 0;i < 10;i++){
   
        if (array[i] == search){
   
            thereBe = true;
            cout << i + 1 << endl;
        }
    }
    if(!thereBe)
        cout << "数组中没有该数";
}

3

参考答案

#include <iostream>
using namespace std;
int main(){
   
    float score[3][5];
    for (int i = 0; i < 3;i++){
   
        float sum = 0;
        for (int j = 0; j < 3; j++){
   
            cin >> score[i][j];
            sum += score[i][j];
        }
        score[i][3] = sum;
        score[i][4] = sum / 3;
    }
    int rank[3];
    if (score[1][3] > score[2][3]){
   
        rank[0] = 1;
        rank[1] = 2;
    }
    else {
   
        rank[0] = 2;
        rank[1] = 1;
    }
    if (score[0][3] > score[ rank[0] ][3]){
   
        rank[1] = rank[0];
        rank[0] = 0;
    }else if (score[0][3] > score[ rank[1] ][3]){
   
        rank[2] = rank[1];
        rank[1] = 0;
    }else rank[2] = 0;
    for (int i = 0; i < 3; i++){
   
        for (int j = 0; j < 5; j++){
   
            cout << score[ rank[i] ][j] << "  ";
        }
        cout << i + 1 << "  " << endl;
    }
}

第六章 编程题

1

参考答案

#include <iostream>
using namespace std;
int main(){
   
    char str1[80], str2[40];
    int p;
    for (int i = 0; i < 80; i++){
   
        str1[i] = 0;
    }
    cin >> str1 >> str2 >> p;
    char *point = &str1[p];
    char *pt;
    for (int i = 0; str2[i] != 0; i++){
   
        for (pt = str1; *pt; pt++);
        for (; pt != point; pt--){
   
            *pt = *(pt - 1);
            
        }
        *point = str2[i];
        point++;
    }
    cout << str1;
}

2

参考答案

#include <iostream>
#include <cstring>
using namespace std;
int main(){
   
    char xnum[40];
    int tnum = 0, sxtn = 1;
    cin >> xnum;
    char *point = &xnum[strlen(xnum) - 1];
    while (*point != '\0'){
   
        if (*point >= '0' && *point <= '9')
            tnum += (*point - '0') * sxtn;
        else if (*point >= 'A' && *point <= 'F')
            tnum += (*point - 'A' + 10) * sxtn;
        else if (*point >= 'a' && *point <= 'f')
            tnum += (*point - 'a' + 10) * sxtn;
        else if (*point == '-')
            tnum = -tnum;
        else {
   
            cout << "input data error!" << endl;
            return 0;
        }
        sxtn *= 16;
        point--;
    }
    cout << tnum << endl;
}

3

参考答案

#include <iostream>
using namespace std;
int main(){
   
    char str[40];
    int sum[64];
    for (int i = 0; i <<
  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值