ARST打卡第145周[145/521]

Algorithm

lc1189_“气球” 的最大数量

思路:
直接计算balloon的这几个字符出现的次数,然后让l和o字符的次数除以2(右移位运算)
然后取b,a,l,o,n的最小值即为答案ans

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
int maxNumberOfBalloons(string text) {
// b, a, l(>> 1), o(>> 1), n
int tmp[5] = {0, 0, 0, 0, 0};
for (auto x : text) {
if (x == 'b') {
tmp[0]++;
} else if (x == 'a') {
tmp[1]++;
} else if (x == 'l') {
tmp[2]++;
} else if (x == 'o') {
tmp[3]++;
} else if (x == 'n') {
tmp[4]++;
}
}
tmp[2] = tmp[2] >> 1;
tmp[3] = tmp[3] >> 1;
int ans = tmp[0];
for (int i = 1; i < 5; i++) {
ans = min(ans, tmp[i]);
}
return ans;
}
};

Review

8 important lessons I’ve learned so far in my career

程序员不只有编码,还有帮助其他同事,互学相长
多鼓励他人
积极去行动积累经验,而不是因为缺乏经验而不去行动
英语不好也不要怕,能用就行
大厂员工不一定全都比你厉害,所以自己努力成长即可
理解商业模式,理解如何盈利,帮助你更好地开发软件
注意每天的坐姿,保持健康
学会把自己的创意转化成一个单独的产品,不管是web还是Android

Tips

VMware、KVM、Docker如何支撑云技术发展?

Share-vsftpd日志打印源码分析logging.c

vsftpd 源码的接口都有注释,很好看懂,自成体系:

初始化

  • void vsf_log_init(struct vsf_session* p_sess);
    只在main函数中调用一次

成体系的一个日志打印

  • void vsf_log_start_entry(struct vsf_session* p_sess, enum EVSFLogEntryType what);
  • int vsf_log_entry_pending(struct vsf_session* p_sess);
  • void vsf_log_clear_entry(struct vsf_session* p_sess);
  • void vsf_log_do_log(struct vsf_session* p_sess, int succeeded);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
static void
handle_dele(struct vsf_session* p_sess)
{
int retval;
resolve_tilde(&p_sess->ftp_arg_str, p_sess);
vsf_log_start_entry(p_sess, kVSFLogEntryDelete);
str_copy(&p_sess->log_str, &p_sess->ftp_arg_str);
prepend_path_to_filename(&p_sess->log_str);
if (!vsf_access_check_file(&p_sess->ftp_arg_str))
{
vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
return;
}
retval = str_unlink(&p_sess->ftp_arg_str);
if (retval != 0)
{
vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Delete operation failed.");
}
else
{
vsf_log_do_log(p_sess, 1);
vsf_cmdio_write(p_sess, FTP_DELEOK, "Delete operation successful.");
}
}
1
2
3
4
if (vsf_log_entry_pending(p_sess))
{
vsf_log_do_log(p_sess, 0);
}

单独打印的行

配合下面两个一起用

1
2
3
4
5
6
7
8
9
struct mystr str_log_line = INIT_MYSTR;

str_alloc_text(&str_log_line, "Demo logging head: ");
str_append_text(&str_log_line, some_char_str_variable);
str_append_text(&str_log_line, "\n");

vsf_log_line(p_sess, kVSFLogEntryShm, &str_log_line);

str_empty(&str_log_line);
  • void vsf_log_line(struct vsf_session* p_sess, enum EVSFLogEntryType what, struct mystr* p_str);

vsf_log_line(struct vsf_session* p_sess, enum EVSFLogEntryType what, struct mystr* p_str)输出指定字符串
,类似于nfs中的log(what, p_str)