中兴笔试题目总结(一)C++部分

这篇博客汇总了中兴笔试中涉及到的C++编程题目,包括学生分数排序、随机字符串生成、多进制转换、数组中位数查找算法等。同时,还介绍了winsock连接步骤、动态链接库的两种方式以及一个历史情景的UML顺序图绘制问题。
摘要由CSDN通过智能技术生成

一、编程题目

(1)输入某班级学生的姓名、分数,并对分数进行降幂排列并输出;

#include <iostream>
using namespace std;

struct Node
{
        char name[100];
        int score;
        Node *next;
};

void show(Node *head)
{
        while(head)
        {
                cout<<head->name<<" "<<head->score<<endl;
                head = head->next;
        }
}

int linkLen(Node *head)
{
        int len = 0;
        while(head)
        {
                len++;
                head = head->next;
        }
        return len;
}
void sort(Node *head)
{
        int len = linkLen(head);
        for(int j=len-1; j>0; j--)
        {
                Node *tempHead = head;
                for(int i=0; i<j; i++)
                {
                        if(tempHead->score> tempHead->next->score)
                        {
                                char tempName[100];
                                int tempScore;
                                strcpy(tempName,tempHead->next->name);
                                strcpy(tempHead->next->name, tempHead->name);
                                strcpy(tempHead->name, tempName);
                                tempScore = tempHead->next->score;
                                tempHead->next->score = tempHead->score;
                                tempHead->score = tempScore;
                        }
                }
        }
}
int main()
{
        char name[100];
        int score;
        Node *head = NULL;
        Node *tail = NULL;
        scanf("%s %d", name, &score);
        while(score != -1)
        {
                Node *temp = new Node;
                strcpy(temp->name, name);
                temp->score = score;
                temp->next = NULL;
              
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值