性别:女(漫画版)/男(TV版)
身高:12cm
体重:130g
喜欢的颜色:红色
喜欢的食物:合桃
不喜欢的食物:水份多的东西
嗜好:模仿芽美
喜欢的事:常常戴上丝带
芽美的宠物,是一只刺猬
会不会是这个?我记得电视里说它是只针鼠
这两款手机目前还没上市,现在有点过早了吧。。。不过我可以给你我使用过iphone4和HTC g11 这两款的感受,iphone4从牌子上来讲是要比HTC 好一些,因为有好多女孩只认苹果(还有广告因素),从游戏上来讲,苹果差HTC, 我玩稍大一点的游戏就不动了,一直在读取。玩点什么猫、狗的游戏还可以,有些还要付费(因为有些游戏都是为苹果设计的),HTC就不一样直接可以玩实况足球PES,运行很流畅。像素方面就没必要花在心上了,它们始终是手机。外观设计上苹果胜于HTC,HTC g11 把我头痛死了,接听方式是上下滑的,从兜里拿出来不是挂了就是接了(不过现在的机子应该把这缺点该了)。苹果的什么视频通话广告打得也太响了,对方没苹果就当电话使吧(没3G覆盖网络也是)。想玩游戏这类的话目前状况我不太看好iphone5(但是他的有些功能很新奇)。c+n=意思是算命。84行C++代码教你实现洛谷占卜功能
因为我们要随机用户的运势,但是不可能每种运势的几率都相等,所以需要生成带权重的随机数
看到这个需求,先百度一下
百度到了这个代码
#include <iostream>
#include <vector>
#include <numeric>
#include <ctime>
#include <cstdlib>
using std::vector
using std::rand
using std::srand
using std::cout
using std::endl
class MyMath{
public:
vector<int>GetRandomNumWithWeight(vector<int>weight,int number){
int size = weight.size()
vector<int>res
int accumulateValue = accumulate(weight.begin(),weight.end(),0)
srand(time(0))// srand()一定要放在循环外面或者是循环调用的外面,否则的话得到的是相同的随机数
for(int i = 0i <numberi++)
{
int tempSum = 0
int randomNnm = 0
randomNnm = rand() % accumulateValue
//0 ~ weight[0]为1,weight[0]+1 ~ weight[1]为2,依次类推
for(int j = 0j <sizej++)
{
tempSum += weight[j]
cout <<randomNnm <<endl
if(randomNnm <= tempSum)
{
res.push_back(j+1)
break
}
}
}
return res
}
}
int main()
{
vector<int>weight = {1000, 2000, 3000, 1000, 1000, 500, 500, 500, 500 }//数字1-9的权重(这里的数字范围与权重都可以自定义)
MyMath myMath
vector<int>result = myMath.GetRandomNumWithWeight(weight,5)
for(auto const &num:result)
{
cout <<num <<' '
}
cout <<endl
return 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
这个代码可以实现我们想要的随机数效果,
原理很简单,随机数ranIndex生成的区间为权重的总和,根据权重分割子区间。
但代码有点复杂,其实没必要辣么麻烦
所以,还是自己动手,丰衣足食!!!
大概的原理如下:
我们先定义一个整数数组 w_list ,用来存储我们随机的权重。
再定义一个w_sum,用来存权重总和。
再定义一个 lenth 里面存数组的长度int length = sizeof(w_list) / sizeof(int)
然后,一个for循环,用w_sum把w_list的每一项累加起来。
再int一个randVal,把每一份权重存到里面。int randVal = rand() % w_sum
这一步可能有点难懂,举个例子,一共有100份权重(权重总和是100),我们用rand()%100,结果就是每一份权重。
练一下英语:
Let’s start by defining an integer array w_list to store our random weights.
Define w_sum to store the sum of weights.
Int length = sizeof(w_list)/sizeof(int)
Then, a for loop adds up each item of the w_list with w_sum.
Int randVal and store each weight in it. int randVal = rand() % w_sum
This step can be a little confusing, for example, if there are 100 weights (the total weight is 100), we use rand()%100, and the result is each weight.
再int一个rward,接下来一个for循环,
就搞定啦!
这是这一小部分的代码:
for (int i = 0i <lengthi++)
{
if (randVal <= w_list[i])
{
rward = i
break
}
randVal -= w_list[i]
}
1
2
3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
这是随机权重完整一点的代码,加上了随机的名字
srand((unsigned)time(NULL))
int w_list[10] = { 2, 4, 15, 15, 16 , 16 , 25 ,7 , 5 }
string names[10] = { "宇宙超级凶", "大凶", "中平", "小平", "小凶" ,"中吉","小吉","超级吉","中凶" }
int w_sum = 0
int length = sizeof(w_list) / sizeof(int)
for (int i = 0i <lengthi++)
{
w_sum += w_list[i]
}
int randVal = rand() % w_sum
int rward = 0
for (int i = 0i <lengthi++)
{
if (randVal <= w_list[i])
{
rward = i
break
}
randVal -= w_list[i]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
最后输出结果的时候,就直接输出names[rward].c_str()就可以啦!
哈哈!
我凭借我的智慧写出了如此简单的代码!
代码
好了,最核心的东西都讲完了,上完整代码!!(Dev-c++编译通过)
#include <iostream>
#include <time.h>
#include <windows.h>
using namespace std
int rd(int a,int b){
srand((unsigned)time(NULL))
return (rand()%(b-a+1)+a)
}
int main(){
system("color F0")
srand((unsigned)time(NULL))
int w_list[10] = { 2, 4, 15, 15, 16 , 16 , 25 ,7 , 5 }
string names[10] = { "宇宙超级凶", "大凶", "中平", "小平", "小凶" ,"中吉","小吉","超级吉","中凶" }
string yi_list[100][100]={
{"宜:诸事不宜","宜:诸事不宜","宜:诸事不宜","宜:诸事不宜"},
{"宜:装弱","宜:窝在家里","宜:刷题","宜:吃饭"},
{"宜:刷题","宜:开电脑","宜:写作业","宜:睡觉"},
{"宜:发朋友圈","宜:出去玩","宜:打游戏","宜:吃饭"},
{"宜:学习","宜:研究Ruby","宜:研究c#","宜:玩游戏"},
{"宜:膜拜大神","宜:扶老奶奶过马路","宜:玩网游","宜:喝可乐"},
{"宜:吃东西","宜:打sdvx","宜:打开洛谷","宜:出行"},
{"宜:写程序","宜:刷题","宜:偷塔","宜:上CSDN"},
{"宜:扶老奶奶过马路","宜:上课","宜:写作业","宜:写程序"},
}
string yi_shi_list[100][100]={
{"","","",""},
{"谦虚最好了","不出门没有危险","直接AC","吃的饱饱的再学习"},
{"一次AC","发现电脑死机了","全对","睡足了再学习"},
{"点赞量破百","真开心","十连胜","吃饱了"},
{"都会","有了新发现","发现新大陆","直接胜利"},
{"接受神之沐浴","增加RP","犹如神助","真好喝"},
{"吃饱了","今天状态好","发现AC的题变多了","路途顺畅"},
{"不会报错","直接TLE","胜利","发现粉丝涨了200个"},
{"增加RP","听懂了","都会","没有Bug"},
}
string ji_list[100][100]={
{"忌:诸事不宜","忌:诸事不宜","忌:诸事不宜","忌:诸事不宜"},
{"忌:打sdvx","忌:出行","忌:玩手机","忌:吃方便面"},
{"忌:关电脑","忌:开挂","忌:纳财","忌:考试"},
{"忌:膜拜大神","忌:评论","忌:研究Java","忌:吃方便面"},
{"忌:发朋友圈","忌:打开洛谷","忌:研究C++","忌:出行"},
{"忌:探险","忌:发视频","忌:发博客","忌:给别人点赞"},
{"忌:写程序","忌:使用Unity打包exe","忌:装弱","忌:打开CSDN"},
{"忌:点开wx","忌:刷题","忌:打吃鸡","忌:和别人分享你的程序"},
{"忌:纳财","忌:写程序超过500行","忌:断网","忌:检测Bug"},
}
string ji_shi_list[100][100]={
{"","","",""},
{"今天状态不好","路途也许坎坷","好家伙,直接死机","没有调味料"},
{"死机了","被制裁","你没有财运","没及格"},
{"被人嘲笑","被喷","心态崩溃","只有一包调味料"},
{"被人当成买面膜的","大凶","五行代码198个报错","路途坎坷"},
{"你失踪了","被人喷","阅读量1","被人嘲笑"},
{"报错19999+","电脑卡死,发现刚才做的demo全没了","被人看穿","被人陷害"},
{"被人陷害","WA","被队友炸死","别人发现了Bug"},
{"没有财运","99+报错","连不上了","503个Bug"},
}
int w_sum = 0
int length = sizeof(w_list) / sizeof(int)
for (int i = 0i <lengthi++){
w_sum += w_list[i]
}
int randVal = rand() % w_sum
int rward = 0
for (int i = 0i <lengthi++){
if (randVal <= w_list[i]){
rward = i
break
}
randVal -= w_list[i]
}
cout<<"你的运势是:"<<endl
printf(" §%s§
", names[rward].c_str())
for (int ii=0ii<9ii++){
if (names[ii]==names[rward].c_str()){
cout<<" "<<yi_list[ii][rd(0,3)]
cout<<""<<ji_list[ii][rd(0,3)]<<endl
cout<<" "<<yi_shi_list[ii][rd(0,3)]
cout<<""<<ji_shi_list[ii][rd(0,3)]
break