回复 13楼 自学的数学
再写就写完了,剩下的我就不写了。
程序代码:
#include <stdio.h>
#include <string.h>
#define TIMES20 0x0fffff
#define TIMES15 0x007fff
typedef struct info
{
//记录等级
int nLevel;
//记录战绩
int nScore;
//记录连胜 输一场后清零
int nVectory;
}STInfo;
int getVectoryCount(int nScore)
{
int nCount = 0;
while(nScore>0)
{
if((nScore&1)==1)
nCount++;
nScore>>=1;
}
return nCount;
}
void checkRule(int i,STInfo& info)
{
int nCount = 0;
switch(i)
{
//1-18级
case 1:
//计算战绩
printf("用户等级1 - 18 级:\n");
nCount = info.nScore&TIMES15;
printf("用户等级%d级,最近15局胜利%d场,连胜%d场\n", info.nLevel,getVectoryCount(nCount),info.nVectory);
break;
//1-4段
case 2:
//计算战绩
printf("用户等级1-4段:\n");
nCount = info.nScore&TIMES20;
printf("用户等级%d级,最近20局胜利%d场 连胜%d场\n", info.nLevel,getVectoryCount(nCount),info.nVectory);
break;
//5-9段
case 3:
//计算战绩
printf("用户等级5-9段:\n");
nCount = info.nScore&TIMES20;
printf("用户等级%d级,最近20局胜利%d场 连胜%d场\n", info.nLevel,getVectoryCount(nCount),info.nVectory);
break;
}
return ;
}
void checkInfo(STInfo& info)
{
if(info.nLevel <= 18)
{
//1-18级
checkRule(1,info);
}
else if(info.nLevel <= 22)
{
//1-4段
checkRule(2,info);
}
else if(info.nLevel <= 27)
{
//5-9段
checkRule(3,info);
}
return ;
}
int main()
{
STInfo tmp = {18,0xf,4};
checkInfo(tmp);
printf("模拟胜一场\n");
tmp.nVectory += 1;
tmp.nScore <<= 1;
tmp.nScore += 1;
checkInfo(tmp);
printf("模拟输一场\n");
tmp.nScore <<= 1;
tmp.nVectory = 0;
checkInfo(tmp);
return 0;
}
[此贴子已经被作者于2018-7-18 10:03编辑过]