亲宝软件园·资讯

展开

C语言程序员老黄历 C语言实现的程序员老黄历实例

kevin0216 人气:0
想了解C语言实现的程序员老黄历实例的相关内容吗,kevin0216在本文为您仔细讲解C语言程序员老黄历的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C语言,程序员,老黄历,下面大家一起来学习吧。

本文实例讲述了C语言实现的程序员老黄历。分享给大家供大家参考。具体如下:

以前看到过一个jquery程序员老黄历页面,觉得挺有创意的,自己闲着用C语言也写了一个,基本就是随机数的生成,没什么难度,大家随便看看,高手请绕过此篇,控制台程序没什么美观可言,已经尽量弄得好看点了。

#include <stdio.h>
#include <time.h>
int random(int dayseed,int indexseed)
//根据当前时间“天 ”产生伪随机数。 
{
  int i,n;
  n = dayseed % 11117;
  for (i = 0; i < 100 + indexseed; i++) 
  {
    n = n * n;
    n = n % 11117;  // 11117 是个质数
  }
  return n;
}
int isWeekend(struct tm *p) 
{
  return p->tm_wday == 0 || p->tm_wday == 6;
}  
int main(int argc, char *argv[])
{
  char *weeks[6] = {"一","二","三","四","五","六","日"};
  printf("|-------------------------------------|\n");
  printf("|     程序员老黄历beta 1.0    |\n");
  printf("|-------------------------------------|\n");
  time_t timep; 
  struct tm *p; 
  time(&timep); 
  p =localtime(&timep);
  //此函数获得的tm结构体的时间,是已经进行过时区转化为本地时间  
  printf("|-------------------------------------|\n");
  printf("|   今天是%d年%d月%d日 星期%s   |\n",1900+p->tm_year,1+p->tm_mon,p->tm_mday,weeks[p->tm_wday-1]); 
  printf("|-------------------------------------|\n");
  int randNum=random(p->tm_mday, 2);//产生伪随机数
  int randNum1=random(p->tm_mday, 3);
  char *activities[27][3] = { 
  {"写单元测试", "写单元测试将减少出错","写单元测试会降低你的开发效率"},
  {"白天上线", "今天白天上线是安全的","可能导致灾难性后果"},
  {"重构", "代码质量得到提高","你很有可能会陷入泥潭"},
  {"使用%t", "你看起来更有品位","别人会觉得你在装逼"},
  {"跳槽", "该放手时就放手","鉴于当前的经济形势,你的下一份工作未必比现在强"},
  {"招人", "你遇到千里马的可能性大大增加","你只会招到一两个混饭吃的外行"},
  {"面试", "面试官今天心情很好","面试官不爽,会拿你出气"},
  {"提交辞职申请", "公司找到了一个比你更能干更便宜的家伙,巴不得你赶快滚蛋","鉴于当前的经济形势,你的下一份工作未必比现在强"},
  {"申请加薪", "老板今天心情很好","公司正在考虑裁员"},
  {"晚上加班", "晚上是程序员精神最好的时候","", },
  {"命名变量\"%v\"", "",""},
  {"写超过%l行的方法", "你的代码组织的很好,长一点没关系","你的代码将混乱不堪,你自己都看不懂"},
  {"提交代码", "遇到冲突的几率是最低的","你遇到的一大堆冲突会让你觉得自己是不是时间穿越了"},
  {"代码复审", "发现重要问题的几率大大增加","你什么问题都发现不了,白白浪费时间"},
  {"开会", "写代码之余放松一下打个盹,有益健康","你会被扣屎盆子背黑锅"},
  {"晚上上线", "晚上是程序员精神最好的时候","你白天已经筋疲力尽了"},
  {"修复BUG", "你今天对BUG的嗅觉大大提高","新产生的BUG将比修复的更多"},
  {"设计评审", "设计评审会议将变成头脑风暴","人人筋疲力尽,评审就这么过了"},
  {"需求评审", "",""},
  {"打DOTA", "你将有如神助","你会被虐的很惨", },      //这里往下的是周末特定情况 (19-27)
  {"洗澡", "你几天没洗澡了?","会把设计方面的灵感洗掉", },
  {"锻炼一下身体", "","能量没消耗多少,吃得却更多", },
  {"抽烟", "抽烟有利于提神,增加思维敏捷","除非你活够了,死得早点没关系", },
  {"在妹子面前吹牛", "改善你矮穷挫的形象","会被识破", },
  {"撸管", "避免缓冲区溢出","强撸灰飞烟灭", },
  {"浏览成人网站", "重拾对生活的信心","你会心神不宁", },
  {"上微博", "今天发生的事不能错过","会看到令人心情不好的事", },
  {"上AB站", "还需要理由吗?","满屏的兄贵我会说出来?", }
};
  printf("|-------------------------------------|\n");
  if(isWeekend(p))  
  printf("| 宜: \n| %2s\n| %s\n",activities[19+randNum%8][0],activities[randNum%27][1]);
  else
  printf("| 宜: \n| %2s\n| %s\n",activities[randNum%17][0],activities[randNum%27][1]);
  printf("|-------------------------------------|\n");  
  printf("|-------------------------------------|\n");  
  if(isWeekend(p))
  printf("| 不宜:\n| %s\n| %s\n",activities[19+randNum1%8][0],activities[randNum1%27][2]);
  else
  printf("| 不宜:\n| %s\n| %s\n",activities[randNum1%17][0],activities[randNum1%27][2]);
  printf("|-------------------------------------|\n"); 
  /*座位朝向*/  
  char *directions[8]= {"北方","东北方","东方","东南方","南方","西南方","西方","西北方"};
  printf("|-------------------------------------|\n");
  printf("| 座位朝向:面向 %s 写程序,BUG 最少.\n",directions[randNum%8]);
  /*今日宜饮*/
  char *drinks[14] = {"水","茶","红茶","绿茶","咖啡","奶茶","可乐","牛奶","豆奶","果汁","果味汽水","苏打水","运动饮料","酸奶","酒"};  
  printf("|-------------------------------------|\n");
  printf("| 今日宜饮:%s,%s\n",drinks[randNum%14],drinks[randNum1%14]);
  /*女神亲近指数*/
  int ambiguous = randNum%10;
  printf("|-------------------------------------|\n");
  if(10==ambiguous)
  printf("| 亲近指数为10,上吧,骚年!\n");
  else
  printf("| 女神亲近指数:%d \n",ambiguous);
  printf("|-------------------------------------|\n");
  return 0;
}

运行效果如下图所示:

希望本文所述对大家的C语言程序设计有所帮助。

加载全部内容

相关教程
猜你喜欢
用户评论