C++程序片段
DSQ_17
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
获得系统时间
#include #include char ch[128]; time_t t; memset(ch,0x0,128); time(&t); sprintf(ch,"%s", ctime(&t)); 获得的时间以字符串的方式保存在ch中。原创 2013-08-09 18:49:38 · 549 阅读 · 0 评论 -
linux环境变量
按变量的生存周期来划分,Linux变量可分为两类,它们的修改方法如下: (1)永久的:需要修改配置文件,变量永久生效。 常见的配置文件包括: (1-1)/etc/profile:对所有用户生效;此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行;并从/etc/profile.d目录的配置文件中搜集shell的设置 例如:编辑/etc/profile转载 2015-08-31 16:14:36 · 571 阅读 · 0 评论 -
洗牌
bool swap(int *a, int x, int y) { if (x==y) { return false; } int tmp = a[x]; *(a+x) = *(a+y); *(a+y) = tmp; return true; } bool shuffle(int card[], int n) { int idx = 0; for (int i=0; i<原创 2015-08-25 21:40:54 · 725 阅读 · 0 评论 -
[转][转][转][转][转]来自百度知道:管中窥豹虚函数
百度知道一大神onlinewan(六级) 虚函数联系到多态,多态联系到继承。所以本文中都是在继承层次上做文章。没了继承,什么都没得谈。 下面是对C++的虚函数这玩意儿的理解。 一, 什么是虚函数(如果不知道虚函数为何物,但有急切的想知道,那你就应该从这里开始) 简单地说,那些被virtual关键字修饰的成员函数,就是虚函数。虚函数的作用,用专业术语来解释就是实现多态性(Polymor转载 2014-08-15 15:32:31 · 545 阅读 · 0 评论 -
ZOJ 2481 Unique Ascending Array
插入排序: 有点挫~ #include using namespace std; int main() { int n; int arr[100]; int tmp,cnt; while(cin>>n&&n!=0) { cin>>arr[0]; cnt=1; for(int i=1;i<n;i++) { cin>>tmp; int j=cnt-1;原创 2014-05-28 13:27:38 · 625 阅读 · 0 评论 -
【求助】zoj 2476求和水题
据说是个水题,不过还是总WA。。求大神给瞄一眼。 题目描述如下: Total Amount Time Limit: 2 Seconds Memory Limit: 65536 KB Given a list of monetary amounts in a standard format, please calculate the total amount. We de原创 2014-05-25 15:23:05 · 601 阅读 · 0 评论 -
ZOJ 2886 Look and Say
很挫的代码。。。不过思路比较简单 #include #include using namespace std; void inputPos(char *p,int *pos,int num) { int tmp=*pos; int arr[4],i=0; while(num) { arr[i++]=num%10; num/=10; } i--; while(i>=0)原创 2014-06-07 21:18:19 · 889 阅读 · 0 评论 -
zoj 2850 Beautiful Meadow
时间复杂度最好情况和最坏情况一样,都bixu原创 2014-06-07 19:25:00 · 711 阅读 · 0 评论 -
ZOJ 2830 Champion of the swordsmanship
刚开始理解错题意了。。网上找了两个答案,如下:转载 2014-06-05 21:10:09 · 679 阅读 · 0 评论 -
ZOJ 2781 Rounders
字符串处理的。。。原创 2014-06-05 13:50:10 · 680 阅读 · 0 评论 -
ZOJ 2679 OldBill
先贴代码: #include using namespace std; int main() { int testNum; cin>>testNum; int cnt,x,y,z; while(testNum--) { cin>>cnt>>x>>y>>z; int firstBit,lastBit,cost=0; for(firstBit=9;firstBit>0;fir原创 2014-06-02 19:40:12 · 710 阅读 · 0 评论 -
ZOJ 2722 Head-to-head match
刚开始由于溢出tle...原创 2014-06-02 20:17:27 · 827 阅读 · 0 评论 -
一天一道ZOJ
上了四年大学,身为计算机专业出身,代码能力竟然次到如此地步! 从今天开始好好学习C++,一天一道ZOJ---------先从简单的来~ ZOJ1115: 注意接收数字串的长度,long long 也不可,要将接收到的字符串先处理一下,然后再计算。原创 2014-03-20 13:51:33 · 600 阅读 · 0 评论 -
C++中new和malloc的区别
new 是c++中的操作符,malloc是c 中的一个函数new 不止是分配内存,而且会调用类的构造函数,同理delete会调用类的析构函数,而malloc则只分配内存,不会进行初始化类成员的工作,同样free也不会调用析构函数内存泄漏对于malloc或者new都可以检查出来的,区别在于new可以指明是那个文件的那一行,而malloc没有这些信息。new可以看成两个动作: 分配内存(相当于原创 2015-09-02 08:47:04 · 587 阅读 · 0 评论
分享