总是混乱

i++和++i的区别(用代码来解说

#include<iostream>
using namespace std;
int main()
{
	int i=0,j=0;
	cout<<i++<<"  i++"<<endl;//先输出i的值,再给i加一
	cout<<i++<<"  i再++"<<endl; 
	cout<<++j<<"  ++j"<<endl; //先给j加一,再输出j
	cout<<++j<<"  再++j"<<endl; 
	return 0;
} 
//输出结果
/*0  i++
1  i再++
1  ++j
2  再++j */ 

细节

只有string能用 .length(), char不能用。

gets可以读空格
scanf不可以

double ceil(x)
double round(x)
double round(x)

ceil(x) 返回不小于x的最小整数值(返回值为浮点型)向上取整
floor(x) 返回不大于x的最大整数值(返回值为浮点型)向下
round(x) 返回x的四舍五入整数值(返回值为浮点型)

除法中向上取整

#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	ll a=10;
	ll b=3;
	ll c;
	ll d;
	ll e,f;
	c=(long long)ceil((double)a /(double)b);
    d=(a+b-1)/b;
    e=a/b+1;//判断是否整除)
    f=(a-1)/b+1;
    cout<<c<<" "<<d<<" "<<e<<" "<<f;
    
}

关于初始化
const long long inf=-0x3f3f3f3f3f3f3f3f;
const int inf=-0x3f3f3f3f;

猜你喜欢

转载自blog.csdn.net/weixin_43819762/article/details/90813170