- 博客(7)
- 资源 (2)
- 收藏
- 关注
原创 string的find函数返回值和string::npos
先看一种很多人日常使用错误方式string str(“hello world”);int pos=str.find_first_of(“h”);if(pos!=string::npos) // 或者 if(pos!=-1){……// 查找到了} //不存在是find返回-1这样的使用,结果是正常的,但并没有很好的理解string find函数的返回类型和string::npos真正的值。string::find这类型的函数,返回值类型都是string::size_type, 而string
2020-08-11 16:30:21 1995
原创 0808面试
这次猿辅导的面试很糟糕,代码写的很差。这题就是奇偶链表了。#include<iostream>#include<vector>using namespace std;typedef struct ListNode{ int val; ListNode*next; ListNode(int val) :val(val), next(NULL) {}}ListNode;ListNode*fun(ListNode*head){ if (head->nex
2020-08-09 09:59:39 232
原创 安排机器——18TX
我的思路是先对任务排序(按工作时长优先,降序排列)然后对于每个任务(贪心,先选工作时间最长的任务),把时间满足要求且等级满足要求的机器全挑出来,再从中选出等级最低的那一台。#include<iostream>#include<vector>#include<algorithm>using namespace std;const int maxn = 1e5 + 10;struct node { int time, grade; bool isUsed .
2020-08-05 20:26:04 221
原创 huawei练习卷2
这份卷子很简单,三道题全部AC#include<iostream>using namespace std;int main() { int n; while (cin >> n) { if (n == 0) break; //正常的解法 int res = 0; int a, b; while (n >= 3) { a = n / 3;//换的新瓶 b = n % 3;//剩的空瓶 res += a; n = a + b
2020-08-05 15:27:16 178
原创 2016hw卷练习
小结:除了数独这道题写的出了bug,交卷才发现并改正,剩下两题都很轻松。#include<iostream>#include<vector>using namespace std;bool rows[9][10] = { false };//rows[i][j]为true表示第i行的数字j已经被使用了bool cols[9][10] = { false };//cols[i][j]为true表示第i列的数字j已经被使用了bool blocks[9][10] = { fa
2020-08-05 14:28:32 201
原创 pdd笔试题
拼多多的笔试没有报名,但昨天听伙伴们说很难,所以一共4道题,挑了2道会的,自己编了一下。#include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){ int K, N; cin >> K; cin >> N; vector<int>a(N); for (int i = 0; i < N; i++)
2020-08-03 10:21:10 1180
原创 0801笔试
求最大的重叠区间个数#include<iostream>#include<vector>#include<algorithm>using namespace std;class Node{public: int value; int flag; Node(int value, int flag) :value(value), flag(flag) {} bool operator<(const Node&node) { if ..
2020-08-01 21:42:31 250
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人