博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[置顶] 小技巧总结
阅读量:6994 次
发布时间:2019-06-27

本文共 1266 字,大约阅读时间需要 4 分钟。

1.识别空行。

gets(string), if(strlen(string)==0)则是空行

2.结构体的初始化函数可以放在结构体中,这样可以方便地根据需要对某一个节点进行初始化

 

3.常见简写:ans(answer),cnt(count),idx(index,下标),init(initial),str(string),pos(position,位置)

4.生成随机数简单的方法:

#include 
#include
using namespace std;int main(){ for(int i=0;i<5;i++) cout<
<<" "; return 0;}
但rand()总以1为种子,种子固定,产生的随机数总为同一序列的随机数。上面的程序每次执行的结果都是一样的,在我的机子上都是:41 18467 6334 26500 19169。但是rand()还是可以满足某些需求的,比如测试排序STL 的priority_queue的top为最大项时可以通过rand()生成随数检测。

功能更强大的是srand,网上资料很多,此处不表。

5.判断一个数是否整数:有double型数据m,(int)(m+0.5) == m为真则m是整数;注意(int)m == m 可能会带来错误,因为计算机执行运算的时候可能会出现误差

6.复制数组:使用memcpy,头文件string.h。

例程:

#include 
#include
using namespace std;int main(){ int a[5]={0, 1, 2, 3, 4},b[5]={0}; memcpy(a, b, sizeof(int)*3); for(int i=0; i<5; i++) cout<
<<" "; memcpy(a, b, sizeof(b)); for(int i=0; i<5; i++) cout<
<<" "; return 0;}

结果:0 0 0 3 4 0 0 0 0 0

7.模板

#include 
#include
#include
#include
#include
#include
#include
#define LL long long#define MAXI 2147483647#define MAXL 9223372036854775807#define eps (1e-8)#define dg(i) cout << "*" << i << endl;

转载地址:http://ihfvl.baihongyu.com/

你可能感兴趣的文章
动手动脑
查看>>
网络流(二)最大流的增广路算法
查看>>
IIS负载均衡-Application Request Route详解第四篇:使用ARR实现三层部署架构(转载)...
查看>>
TList To DataTable
查看>>
Cache.Insert 方法(摘自MSDN)
查看>>
Duck typing
查看>>
每日一记--索引/过滤器
查看>>
Struts2的CRUD操作
查看>>
A Simple Problem with Integers
查看>>
WampServer中MySQL中文乱码解决
查看>>
Codeforces-938D-Buy a Ticket(最短路设虚拟节点+Dijk优先队列优化)
查看>>
电商打折套路分析 —— Python数据分析练习
查看>>
HTTP请求、响应报文格式
查看>>
zendstudio中出现中文乱码的解决方法
查看>>
服务器端与客户端TCP连接入门(一)
查看>>
lombok使用方法
查看>>
多线程基础
查看>>
1028: C语言程序设计教程(第三版)课后习题8.2
查看>>
批量更新软连接脚本
查看>>
Linux 文件和目录的属性
查看>>