|
|
贴子作者:周华良 |
发贴日期:2004-6-30 09:42 |
阅读次数:647 |
回复条数:1 |
所属版块:灌水乐园 |
最后回复日期:2004-7-20 04:13 |
|
|
标题:搞笑的C++程序 |
内容: |
|
#define AND &&
RESULT love(boy, girl)
{ if( boy.有房() AND boy.有车() ) { boy.Set(Nothing); return girl.嫁给(boy); } else if( girl.愿意等() ) { next_year: for( day=1; day<=365; day++) { if( day == 情人节 ) if( boy.GiveGirl(玫瑰) ) girl.感情++; else girl.感情--; if( day == girl.生日) if( boy.GiveGirl(玫瑰) ) girl.感情++; else girl.感情--; boy.拼命赚钱(); } 年龄++; girl.感情--; if( boy.有房() AND boy.有车() ) { boy.Set(Nothing); return girl.嫁给(boy); } else if( boy.赚钱 > 100,000 AND girl.感情 > 8 ) goto next_year; else return girl.goto( another_boy); } return girl.goto( another_boy); }
|
回复:
贴子作者:lifanxi |
发贴日期:2004-7-20 04:13 |
//改编了一下,基本维持Love这个函数不变,加了一点辅助的定义,现在这个程序可以正常运行了,我在Visual Studio .NET 2003中编译通过。 //输入的姓名能包括英文数字不能有空格,输入Girl的生日时应该输入生日在该年中是第几天,如2月3日就输入34。 //试了一下,成功Marry的机率大约是30%,有70%的机率Girl会离开,苦命呀! //由于本论坛会把两个连续的空格转换成一个中文的空格,所以如果你直接粘贴编译本程序肯定会失败,粘贴后要用替换工具把所有的中文空格 //" "替代成两个英文空格。
#define AND && #include <iostream> #include <string> #include <cmath> #include <ctime> using namespace std;
typedef string RESULT; const int ValentinesDay = 45;
enum Thing { Nothing, Rose };
class Person { public: Person(); bool HasHouse(); bool HasCar(); bool CanWait();
void Set(const Thing & t); void MakeMoney(); string GoTo(const Person & p); string Marry(const Person & p); bool GiveGirl(const Thing & t);
int Love; int Age; int Money; int Birthday; string Name; };
Person::Person() : Love(8), Age(0), Money(0) { srand((unsigned int) time(NULL)); }
bool Person::HasHouse() { if ((double) rand() / RAND_MAX > 0.5) return true; else return false; }
bool Person::HasCar() { if ((double) rand() / RAND_MAX > 0.5) return true; else return false; }
void Person::Set(const Thing & t) { if (t == Nothing) { Money = 0; } }
void Person::MakeMoney() { Money += 100; }
bool Person::CanWait() { if ((double) rand() / RAND_MAX > 0.5) return true; else return false; }
string Person::GoTo(const Person & p) { return Name + " will leave and find another boy!"; }
string Person::Marry(const Person & p) { return Name + " will marry " + p.Name + "!"; }
bool Person::GiveGirl(const Thing & t) { if ((double) rand() / RAND_MAX > 0.5) return true; else return false; }
RESULT Love(Person & boy, Person & girl) { Person AnotherBoy; if (boy.HasHouse() AND boy.HasCar()) { boy.Set(Nothing); return girl.Marry(boy); } else if (girl.CanWait()) { next_year: for (int day=1; day<=365; day++) { if (day == ValentinesDay) if (boy.GiveGirl(Rose)) girl.Love++; else girl.Love--; if (day == girl.Birthday) if (boy.GiveGirl(Rose)) girl.Love++; else girl.Love--; boy.MakeMoney(); } boy.Age++; girl.Age++; girl.Love--; if (boy.HasHouse() AND boy.HasCar()) { boy.Set(Nothing); return girl.Marry(boy); } else if (boy.Money > 100000 AND girl.Love > 8) goto next_year; else return girl.GoTo(AnotherBoy); } return girl.GoTo(AnotherBoy); }
int main() { Person boy; cout << "Please input the boy's name:"; cin >> boy.Name;
Person girl; cout << "Please input the girl's name:"; cin >> girl.Name; cout << "Please input the girl's birthday:"; cin >> girl.Birthday;
cout << "The result is:"; cout << Love(boy, girl) << endl;
system("pause");
return 0; } |
您尚未登陆网站,不能回复贴子!
|
|
|