博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
服务端面试题
阅读量:2058 次
发布时间:2019-04-29

本文共 2072 字,大约阅读时间需要 6 分钟。

1.随机产生5个数,这5个数每个数的范围都在[10,35]之间,5个数的和是定值100,尽量让5个数的概率随机,算法尽量高效,写出算法??

#include 
#include
#include
using namespace std;int main(){ srand((unsigned)time(NULL)); int a, b, c, d, e; a = (rand() % 26) + 10; b = (rand() % 26) + 10; if (a != 35 || b != 35) { c = (rand() % 26) + 10; while ((100 - a - b - c) / 2<10 || (100 - a - b - c) / 2 > 35) c = (rand() % 26) + 10; d = (rand() % 26) + 10; while ((100 - a - b - c - d)<10 || (100 - a - b - c - d)>35) d = (rand() % 26) + 10; e = 100 - a - b - c - d; } else { c = d = e = 10; } cout << a << endl; cout << b << endl; cout << c << endl; cout << d << endl; cout << e << endl; system("pause"); return 0;}

2.不使用库函数实现数组里所有元素求和

1)使用中间变量实现

2)不使用中间变量实现

#include 
using namespace std;int sum1(int a[], int len);int sum2(int a[], int len);int main(){ int a[] = { 1, 2, 3, 4, 5, 6, 7,8,9,10 }; cout << sum2(a, sizeof(a) / sizeof(a[0])) << endl; system("pause"); return 0;}int sum1(int a[], int len){ int sum = 0; for (int i = 0; i < len; i++) { sum += a[i]; } return sum;}int sum2(int a[], int len){ if (len == 0) return 0; if (len == 1) return a[0]; return sum2(a, len - 1) + a[len - 1];}

3.游戏里面每个玩家有自己的id,名字,等级,职业,所属帮派,而且每个玩家有多只宠物,而每只宠物有自己的名字,等级,种类

1)用SQL语句创建玩家表

2)根据宠物种类统计玩家等级在40-49之间拥有宠物的数量

玩家表:

CREATE TABLE `player_role` (   `id` int(11) NOT NULL,   `name` varchar(25) DEFAULT NULL,   `profession` varchar(10) DEFAULT NULL,   `guild` varchar(25) DEFAULT NULL,   `level` int(11) DEFAULT NULL,   PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT

宠物表:

CREATE TABLE `pet` (  `id` int(11) NOT NULL,  `pet_name` varchar(25) DEFAULT NULL,  `level` int(10) DEFAULT NULL,  `kind` varchar(10) DEFAULT NULL,  `player_id` int(11) DEFAULT NULL,  PRIMARY KEY (`id`),  KEY `player_id` (`player_id`),  CONSTRAINT `pet_ibfk_1` FOREIGN KEY (`player_id`) REFERENCES `player_role` (`id`)  ) ENGINE=InnoDB DEFAULT CHARSET=utf8

统计宠物数量:

select c.kind, count(*) as count from (select b.* from player_role a,pet b where a.id = b.player_id and (a.level >=40 and a.level <=49)) c group by c.kind;

转载地址:http://csxlf.baihongyu.com/

你可能感兴趣的文章
【英语】软件开发常用英语词汇
查看>>
Fiddler 抓包工具总结
查看>>
【雅思】雅思需要购买和准备的学习资料
查看>>
【雅思】雅思写作作业(1)
查看>>
【雅思】【大作文】【审题作业】关于同不同意的审题作业(重点)
查看>>
【Loadrunner】通过loadrunner录制时候有事件但是白页无法出来登录页怎么办?
查看>>
【English】【托业】【四六级】写译高频词汇
查看>>
【托业】【新东方全真模拟】01~02-----P5~6
查看>>
【托业】【新东方全真模拟】03~04-----P5~6
查看>>
【托业】【新东方托业全真模拟】TEST05~06-----P5~6
查看>>
【托业】【新东方托业全真模拟】TEST09~10-----P5~6
查看>>
【托业】【新东方托业全真模拟】TEST07~08-----P5~6
查看>>
solver及其配置
查看>>
JAVA多线程之volatile 与 synchronized 的比较
查看>>
Java集合框架知识梳理
查看>>
笔试题(一)—— java基础
查看>>
Redis学习笔记(二)— 在linux下搭建redis服务器
查看>>
Redis学习笔记(三)—— 使用redis客户端连接windows和linux下的redis并解决无法连接redis的问题
查看>>
Intellij IDEA使用(一)—— 安装Intellij IDEA(ideaIU-2017.2.3)并完成Intellij IDEA的简单配置
查看>>
Intellij IDEA使用(二)—— 在Intellij IDEA中配置JDK(SDK)
查看>>