1.
printf("%.1lf\n",8.0/5.0);
2.
const double PI = 4.0 * atan(1.0);
3.
sin与cos都是用的弧度
n/180.0*PI;
4. 四舍五入判断整数x
double x;
floor(x+0.5)==x;
5. 计时函数
#include <time.h>
cout<<(double)clock()/CLOCKS_PER_SEC<<endl;
6.管道输入
echo 20 | ./a.out
7. 重定向读写文件
#define LOCAL
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
g++ hi.cpp -DLOCAL
8. fopen法读写文件
FILE *fin, *fout;
fin = fopen("data.in","r");
fout = fopen("data.out","w");
scanf-----> fscanf(fin,);
printf-----> fprintf(fout,);
fclose(fin);
fclose(fout);
-------------------------------------------
#include <fstream>
ifstream fin("data.in");
ofstream fout("data.out");
fin>>a>>b;
fout<<a+b;
9. 数的范围
long long -2^63~2^63-1 比 -10^19~10^19略窄 %lld
int -2^31~2^31-1 比 -2*10^9~2*10^9略宽
10. 数组元素复制
#include <string.h>
int a[MAXN],b[MAXN];
memcpy(b,a,sizeof(int)*k);
11. 写入字符串,从字符串读入
//写字符串
#include <string.h>
char buf[100];
sprintf(buf,"%d%d%d",a,b,c);
strchr(s,buf[i])在字符串s中查询 char,返回的是指针;
//读字符串
char s[50];
cin>>s;
sscanf(s,"%d:%d:%d",&HH,&MM,&SS);
-----------------------------------------------------------------
#include <sstream>
char s[1000];
cin.getline(s,1000,'\n');
stringstream ss(s);
__________________________________
string s;
getline(cin,s);
stringstream ss(s);
ss>>a>>b;
//string的字符串与c字符串的转化
char s[100];
string(s);
s.c_str();
12. 读入字符串(含空格的一句话)
o1.
fgetc(fin);返回int 或 EOF
getchar() == fgetc(stdin);
o2.
char buf[MAXN];
fgets(buf, MAXN,fin);完整地读取一行
13. 字符的处理
#include <ctype.h>
isalpha(); toupper(); tolower(); isdigit(); isprint();
14. 批处理测试
//test.sh
while true; do
./r >input
./a < input >output.a
./b < input >output.b
diff output.a output.b
if [ $? -ne 0 ] ;then break; fi
done
然后将文件 chmod +x test.sh 后 ./test.sh
15. assert的使用
#include <assert.h>
assert(x>=0);//不满足条件时程序强制终止
printf("%.1lf\n",8.0/5.0);
2.
const double PI = 4.0 * atan(1.0);
3.
sin与cos都是用的弧度
n/180.0*PI;
4. 四舍五入判断整数x
double x;
floor(x+0.5)==x;
5. 计时函数
#include <time.h>
cout<<(double)clock()/CLOCKS_PER_SEC<<endl;
6.管道输入
echo 20 | ./a.out
7. 重定向读写文件
#define LOCAL
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
g++ hi.cpp -DLOCAL
8. fopen法读写文件
FILE *fin, *fout;
fin = fopen("data.in","r");
fout = fopen("data.out","w");
scanf-----> fscanf(fin,);
printf-----> fprintf(fout,);
fclose(fin);
fclose(fout);
-------------------------------------------
#include <fstream>
ifstream fin("data.in");
ofstream fout("data.out");
fin>>a>>b;
fout<<a+b;
9. 数的范围
long long -2^63~2^63-1 比 -10^19~10^19略窄 %lld
int -2^31~2^31-1 比 -2*10^9~2*10^9略宽
10. 数组元素复制
#include <string.h>
int a[MAXN],b[MAXN];
memcpy(b,a,sizeof(int)*k);
11. 写入字符串,从字符串读入
//写字符串
#include <string.h>
char buf[100];
sprintf(buf,"%d%d%d",a,b,c);
strchr(s,buf[i])在字符串s中查询 char,返回的是指针;
//读字符串
char s[50];
cin>>s;
sscanf(s,"%d:%d:%d",&HH,&MM,&SS);
-----------------------------------------------------------------
#include <sstream>
char s[1000];
cin.getline(s,1000,'\n');
stringstream ss(s);
__________________________________
string s;
getline(cin,s);
stringstream ss(s);
ss>>a>>b;
//string的字符串与c字符串的转化
char s[100];
string(s);
s.c_str();
12. 读入字符串(含空格的一句话)
o1.
fgetc(fin);返回int 或 EOF
getchar() == fgetc(stdin);
o2.
char buf[MAXN];
fgets(buf, MAXN,fin);完整地读取一行
13. 字符的处理
#include <ctype.h>
isalpha(); toupper(); tolower(); isdigit(); isprint();
14. 批处理测试
//test.sh
while true; do
./r >input
./a < input >output.a
./b < input >output.b
diff output.a output.b
if [ $? -ne 0 ] ;then break; fi
done
然后将文件 chmod +x test.sh 后 ./test.sh
15. assert的使用
#include <assert.h>
assert(x>=0);//不满足条件时程序强制终止