C++ 稀疏表的练习

时间:2019-11-06 20:23 作者:DoubleQ 阅读数:555

C++ 稀疏表的练习

代码

#include <iostream>

using namespace std;

string names[] = { "张三","李四","王五","赵六" };

string subjects[] = { "语文","数学","英语" };

double scores[4][3] = { {68,91,88},{100,59,80},{99,55,80},{80,66,63} };

int findValue(string values[],int num, string value)

{

    for (int i = 0; i < num; i++)

    {

        if (values[i] == value)

        {

            return i;

        }

    }

    return -1;

}

int printScore(string name, string subject)

{

    int nameId = findValue(names, 4, name);

    if (nameId == -1) return -1;

    int subjectId = findValue(subjects, 3, subject);

    if (subjectId == -1) return -1;

    return scores[nameId][subjectId];

}

int main()

{

    cout << "张三的语文成绩是:\n";

    cout << printScore("张三", "语文")<<"\n";

    cout << "张三的数学成绩是:\n";

    cout << printScore("张三", "数学") << "\n";

    cout << "张三的英语成绩是:\n";

    cout << printScore("张三", "英语") << "\n";

    cout << "张三的总分是:\n";

    int allScore=printScore("张三", "英语")+

        printScore("张三", "英语")+

        printScore("张三", "英语");

    cout << allScore;

 

}

实现方法

image.png



推荐文章

[推荐] .NET Core 学习资料精选:入门

[推荐] 数据库常见死锁原因及处理

[推荐] C# 设置Excel数据自适应行高、列宽的2种情况 (转)

[推荐] C++ vector 和set结合数字去重练习

[推荐] win7 .net core 部署 The library hostfxr.dll was found, but loading it from C:\<path_to_app>\hostfxr.dll failed

[推荐] JdbcTemplate多数据源使用

[推荐] 深入学习Redis(2):持久化

[推荐] asp.net core系列 67 Web压力测试工具WCAT

[推荐] .Net Core 2.0 获取客户端IP地址

[推荐] 第七天 让你的container实现跨主机访问

[推荐] 8天玩转并行开发——第八天 用VS性能向导解剖你的程序

[推荐] nodejs app.use(express.static) 静态文件托管 (四)

[推荐] C++ 稀疏表的练习

[推荐] C++ Lambda表达式练习

[推荐] asp.net core系列 33 EF查询数据 (2)

[推荐] Spring Boot 2 (五):Docker Compose + Spring Boot + Nginx + Mysql 实践

[推荐] 试试发布

[推荐] C++中 *p++ 到底是 *(p++) 还是 (*p)++ 1. 猜想

[推荐] JavaWeb-Log4j: WARN No appenders could be found for logger

[推荐] C++ 模板练习


评论列表



注册用户登录后才能发表评论,请登录注册,访问 博客首页