这样下去泰迪熊会成为一代编程高手吗?

tkminigame 2009-07-10 06:45:47
如题,泰迪熊在登录CSDN以后开始学习编程。流程如下:先搜索论坛上的问题,看自己是否能解决得了。如果解决得了则解决问题,获得问题的积分,如果解决不了,则将这个问题放入网摘,进行日后学习。学习了网摘的问题后,可以将问题积分的20%转换成相应的经验值,经验值可以提高泰迪熊解决问题的速度和成功率。泰迪熊只研究三种语言领域的问题:C,JAVA,PHP。当它成功解决问题的时候,就会赏给自己一块又香又甜的蜂蜜!如果即没有问题也没有网摘学习,泰迪熊就会在论坛上灌水,你认为这样它能够成为一代高手吗?




#include <process.h>
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <string.h>
#include <queue>
#include <time.h>
#include <stdarg.h>
#include <math.h>
using namespace std;
static const char* qType[] = {"C/C++","JAVA","PHP"};
struct question{
int type;
int score;
};
typedef queue<question> questions;
questions unsolved;

class Coder{
public:
char name[256];
int score;
int exp[3];
questions bookmark;

Coder(const char* name):score(0){
strcpy_s(this->name,256,name);
::memset(exp,0,sizeof(exp));
}

void LogOnCSDN();
bool solve(question& q);
void study(question& q);
void say(char* format,...);
void info(char* format,...);
void update();
void poolingWater(){say("%s is pooling water....",name);Sleep(3000);};
};
void Coder::say(char* format,...){
char s[512];
va_list arg;
int done;
va_start (arg, format);
done = ::vsnprintf_s(s, 512, 512, format, arg);
va_end (arg);

printf("[%s]: %s\n",this->name,s);
};
void Coder::info(char* format,...){
char s[512];
va_list arg;
int done;
va_start (arg, format);
done = ::vsnprintf_s(s, 512, 512, format, arg);
va_end (arg);
printf("[CSDN]: %s",s);
};
void Coder::update(){
char words[512];
::sprintf_s(words,512,"Now %s\'s score is %d.unsolved/bookmarks:(%d/%d).\n\n",name,score,unsolved.size(),bookmark.size());
info(words);
}
void Coder::study(question& q){
char words[512];
::sprintf_s(words,512,"%s is learning %s.",name,qType[q.type]);
info(words);
for(int i = 0;i<5;i++){
::Sleep(1000);
printf(".");
}
printf("\n");
exp[q.type]+=q.score/5;
::sprintf_s(words,512,"%s got %d exp on %s.(%d)\n\n",name,q.score/5,qType[q.type],exp[q.type]);
info(words);
}
bool Coder::solve(question& q){
//spend sometime to check the promblem is soluble
Sleep(500);
//raise one percent per 50 point
double successRate = exp[q.type]/5000.0;
//make it high but not too high
if(successRate>0.95) successRate = 0.95;
if(rand()>(int)(((double)RAND_MAX)*successRate)){
return false;
}
int solveTime = (255-exp[q.type])*10;
if(solveTime<=500) solveTime= 500;
::Sleep(solveTime);
return true;
}

void Coder::LogOnCSDN(){
say("Hi!I'm a new fish on CSDN!My name is %s.\n",name);
while(true){
update();
::Sleep(1000);
if(!unsolved.empty()){
info("%s is trying to solve a problem.\n",name);
question q = ::unsolved.front();
unsolved.pop();
if(solve(q)){
say("I just resolved one %s problem!I must reward myself a piece of honey!",qType[q.type]);
this->score+=q.score;
say("umm,umm,umm,It's yummy!");
Sleep(100);
}else{
say("Oh my bee!I can\'t solve this problem!I must add it to my bookmark!");
bookmark.push(q);
}
::Sleep(500);
}else if(!bookmark.empty()){
//learning
question q = bookmark.front();
this->study(q);
bookmark.pop();

}else{
this->poolingWater();
}

}
}
void generateQuestion(void* p){

time_t t;
::time(&t);
::srand((UINT)t);
while(true){
question q = {rand()%5,(rand()%10+1)*10};
if(q.type<3){
::unsolved.push(q);
}
Sleep(3000);
}

::_endthread();
}

int _tmain(int argc, _TCHAR* argv[])
{
time_t t;
::time(&t);
::srand((UINT)t);
::_beginthread(generateQuestion,0,0);
Coder teddyBear("Teddy Bear");
teddyBear.LogOnCSDN();

return 0;
}


...全文
141 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingzhe2001 2009-08-03
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 cngameboy 的回复:]
这个类写的不错. 咽咽咽有思想了. 但楼主的技术还不太好. 数据对齐,还有全局变量本身就是static,不用再加这个.

Love your Teddy Bear. ^_^
[/Quote]
虽然全局变量是static,但是在全局变量前加static可以保证这个变量只有在这个文件的scope里才可以访问。
ForestDB 2009-07-13
  • 打赏
  • 举报
回复
觉得LZ是来放分的。
芒果仔 2009-07-13
  • 打赏
  • 举报
回复
哪里有C++的影子?
yangyunzhao 2009-07-13
  • 打赏
  • 举报
回复
楼主强人啊
CNGameBoy 2009-07-13
  • 打赏
  • 举报
回复
可以写一个这样的虚拟人生啊! CSDN人生... 哈哈, 我很有兴趣...
CNGameBoy 2009-07-13
  • 打赏
  • 举报
回复
这个类写的不错. 咽咽咽有思想了. 但楼主的技术还不太好. 数据对齐,还有全局变量本身就是static,不用再加这个.

Love your Teddy Bear. ^_^
CNGameBoy 2009-07-13
  • 打赏
  • 举报
回复
喜欢楼主, 楼主你太牛B了.顶一下! 哈哈, 爱死你了...
kkun_3yue3 2009-07-13
  • 打赏
  • 举报
回复
fatal error C1083: 无法打开包括文件:“stdio”: No such file or directory
Mynameiswuyihao 2009-07-13
  • 打赏
  • 举报
回复
哈哈,little teddy
hemiya 2009-07-13
  • 打赏
  • 举报
回复
o
rainbow_free 2009-07-13
  • 打赏
  • 举报
回复
帮顶!
amossavez 2009-07-13
  • 打赏
  • 举报
回复
good!楼主有想法
superbtl 2009-07-13
  • 打赏
  • 举报
回复
管你的 JF先
  • 打赏
  • 举报
回复
LZ已经走火入魔了。。。
liyang_1949 2009-07-13
  • 打赏
  • 举报
回复
看来要运行下才明白楼主想干啥。。。。。。。。。。。。。。
sea_spray 2009-07-11
  • 打赏
  • 举报
回复
帮顶
sbgeqh 2009-07-11
  • 打赏
  • 举报
回复
太牛了~~~~
tkminigame 2009-07-11
  • 打赏
  • 举报
回复
这个程序讲了一个故事。copy到你的新建工程里面跑一下啊。
坚持就是幸福 2009-07-11
  • 打赏
  • 举报
回复
也不明白楼主想表达什么意思?
机智的呆呆 2009-07-10
  • 打赏
  • 举报
回复
加载更多回复(6)

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧