總是混亂

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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章