vector 容量capacity size 不同
#include<iostream>
#include<cstring>
#include<algorithm>
#include<ctime>
using namespace std;
int main()
{
clock_t t = clock();
int l = 1;
while(1)
{
l ++;
if(l > 4e8) break; // 4亿
}
cout << (double)(clock() - t) / 1000 / 1000 << endl;
vector<int> a;
l = 1;
t = clock();
while(1)
{
a.push_back(l);
l ++;
if(l > 1e5) break;
}
cout << (double)(clock() - t) / 1000 / 1000 << endl;
printf("a.capacity = %d\n", a.capacity());
printf("a.data = %lld\n", a.data());
printf("a.front = %d\n", a.front());
printf("a.back = %d\n", a.back());
printf("a.begin = %lld\n", a.begin());
printf("a.end = %lld\n", a.end());
t = clock();
printf("a.size = %d\n", a.size());
cout << (double)(clock() - t) / 1000 / 1000 << endl;
return 0;
}
————
选中目标 shift ctrl L 选中所有相同目标
使用 sstream
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
using namespace std;
int main()
{
stringstream sin;
string line;
getline(cin, line);
sin << line;
string str;
while(sin >> str) cout << str << endl;
return 0;
}
判断闰年
bool isLeapYear(int year) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return true;
return false;
}