杂项(知识点、实现、技巧)
TP
- 读取 ==带空格== 字符串(字符串输入)
- stringstream类
- 清空缓冲区
- ASCII表
- isdigit( )函数
- 好用的一些 #define
- 符号(运算符)优先级
- VS-2019舍去scanf_s
- next_permutation函数和prev_permutation函数
- 方便的二分函数
- 由 数据范围 反推 算法
- vector / map等搜索特定元素删减的方法
- C++ STL中常见容器的时间复杂度
- 1 G B = 1024 M B , 1 M B = 1024 K B , 1 K B = 1024 B , 1 B = 8 b 1GB=1024MB,1MB=1024KB,1KB=1024B,1B=8b 1GB=1024MB,1MB=1024KB,1KB=1024B,1B=8b
- 创造题目数据/上传题目/编写题目(造数据)
读取 带空格 字符串(字符串输入)
具体请参考这篇神牛博客: C++读入详解之终极无惑




第一个参数是数组头地址,第二个是输入的最大长度
- getline在读到 ‘\n’ 符后停止读入,同时不会把换行符留在缓冲区
- cin.get () 会把换行符留在缓冲区
- cin有自动忽略空格的特性,不要再用getchar()!
stringstream类
-
完成流的输入、输出和输入输出操作,永远滴绳
-
包含在头文件
#include中 -
如果对于一组int数字数据,不清楚它有多少个数字,只是让你输入,又或者不清楚有多少个空格,那此时就是这个库发挥作用的时候


相关文章:
- 1
- 2
清空缓冲区
cin.ignore ( ) 的用法:
- cin.ignore()函数中有两个参数,分别为数值型的 a 和 字符型的 ch ,即 cin.ignore( a, ch ) 。它表示从输入流 cin 中提取字符,提取的字符被忽略,不被使用。而每抛弃一个字符,它都要进行计数和比较字符:如果计数值达到 a 或者被抛弃的字符是 ch ,则cin.ignore() 函数执行终止;否则,它继续等待。
- 例如可以这么用,
cin.ignore(1024,'\n'),通常把第一个参数设置得足够大,这样实际上是为了只有第二个参数 ‘\n’ 起作用,所以这一句就是把回车(包括回车)之前的所以字符从输入缓冲流中清除出去。

ASCII表
isdigit( )函数

用以判断单个字符是否为数字字符,无需定义
好用的一些 #define
#define mem(a,b) memset(a,b,sizeof a)
#define cinios (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))
#define RT double rtime = 1.0 * clock() / CLOCKS_PER_SEC; cout<<"\nRuntime: "<<rtime<< " s.\n";
#define debug(x) cout<<"target is "<<x<<endl
#define forr(a,b,c) for(int a=b;a<=c;a++)
#define all(a) a.begin(),a.end()
#define oper(a) (operator<(const a& ee)const)
#define endl "\n"typedef long long ll;
typedef pair<int, int> PII;
符号(运算符)优先级

VS-2019舍去scanf_s
_CRT_SECURE_NO_WARNINGS
next_permutation函数和prev_permutation函数

next_permutation函数将按字母表顺序生成给定序列的下一个较大的排列,直到整个序列为降序为止。prev_permutation函数与之相反,是生成给定序列的上一个较小的排列。
方便的二分函数

由 数据范围 反推 算法

vector / map等搜索特定元素删减的方法

遍历删除是错的!!!

正确的方法:重置迭代器(地址修改)
像链表一样,上一个指向下下个

也可以删除某个区域内的元素,不用调用迭代器

不会删除末尾那个数,是半包含关系
C++ STL中常见容器的时间复杂度

1 G B = 1024 M B , 1 M B = 1024 K B , 1 K B = 1024 B , 1 B = 8 b 1GB=1024MB,1MB=1024KB,1KB=1024B,1B=8b 1GB=1024MB,1MB=1024KB,1KB=1024B,1B=8b
创造题目数据/上传题目/编写题目(造数据)

srand(time(0));//随机数freopen("1.in", "w", stdout);//输入数据freopen("1.in", "r", stdin);freopen("1.out", "w", stdout);//解决输出//map处理名单map<string, int> mp;string s;for (int i = 1; i <= 63; i++){cin >> s;mp[s]++;}while (cin >> s){mp[s]--;}for (auto j : mp)if (j.second) {cout << j.first << ' ' << j.second << endl;}
#include using namespace std;typedef long long LL;const int N = 1000010;LL a[N], sum[N], sub[N];
int n, q;
LL b[N];void dianin()
{//想要造什么数据把它输出来就行LL a, b, c;LL s[5];a = (rand() % 1000 + 1) * (rand() % 1000 + 1) % 1000000000 + 1;b = (rand() % 1000 + 1) * (rand() % 1000 + 1) % 1000000000 + 1;c = (rand() % 1000 + 1) * (rand() % 1000 + 1) % 1000000000 + 1;s[0] = a + b, s[1] = a + c, s[2] = b + c, s[3] = a + b + c;for (int i = 0; i < 4; i ++){int t = rand() % 4, tt = rand() % 4;swap(s[t], s[tt]);}cout << s[0] << ' ' << s[1] << ' ' << s[2] << ' ' << s[3] << '\n';}void dianout()
{//解题代码(标程)int a[5];for (int i = 1; i <= 4; i ++) cin >> a[i];sort(a + 1, a + 5);int b[10];b[0] = a[1] + a[2] - a[4];b[1] = a[1] + a[3] - a[4];b[2] = a[2] + a[3] - a[4];sort(b, b + 3);cout << b[0] << ' ' << b[1] << ' ' << b[2] << '\n';}int main()
{srand(time(0));freopen("1.in", "w", stdout);dianin();freopen("1.in", "r", stdin);freopen("1.out", "w", stdout);dianout();freopen("2.in", "w", stdout);dianin();freopen("2.in", "r", stdin);freopen("2.out", "w", stdout);dianout();freopen("3.in", "w", stdout);dianin();freopen("3.in", "r", stdin);freopen("3.out", "w", stdout);dianout();freopen("4.in", "w", stdout);dianin();freopen("4.in", "r", stdin);freopen("4.out", "w", stdout);dianout();freopen("5.in", "w", stdout);dianin();freopen("5.in", "r", stdin);freopen("5.out", "w", stdout);dianout();freopen("6.in", "w", stdout);dianin();freopen("6.in", "r", stdin);freopen("6.out", "w", stdout);dianout();freopen("7.in", "w", stdout);dianin();freopen("7.in", "r", stdin);freopen("7.out", "w", stdout);dianout();freopen("8.in", "w", stdout);dianin();freopen("8.in", "r", stdin);freopen("8.out", "w", stdout);dianout();freopen("9.in", "w", stdout);dianin();freopen("9.in", "r", stdin);freopen("9.out", "w", stdout);dianout();freopen("10.in", "w", stdout);dianin();freopen("10.in", "r", stdin);freopen("10.out", "w", stdout);dianout();return 0;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
