浙江杭州华诺康笔试(嵌入式软件)【C++】

一、选择题

1.

const char *p,char const *p和char *const p区别(面试题常见)-CSDN博客

2.

#include <iostream>
using namespace std;

void f(int a = []()
{
	static int b = 1;
	return b++;
}())
{
	std:cout << a;
}

int main()
{
	f();
	f();
	
	return 0;
}

输出结果为12

3.

C++中的std- CSDN搜索

3.以下错误的行为是D

A. std:cout<<"测试\n";

B. operator<<(std::cout,"测试\n");

C. endl(std::cout);

D. std::cout<<endl;

D选项中endl前也需要加std::

endl和\n都是换行的 endl 是 iostream中的预设操纵符 endl在输出流中插入一个换行符然后刷新缓冲区(endl在iostream中执行的是一个操作而不是提供数据) endl 出了写\n进输出流外还调用了flush函数 刷新缓冲区 让数据直接显示或写进文件 如果写\n 就不一定立即显示因为数据可能还存在缓冲区没有立即写入设备 为了提高效率可以写\n 这样会更快。

4.下面对静态数据成员的描述中,正确的是( D )。
A) 静态数据成员可以在类体内进行初始化
B) 静态数据成员不可以通过类的对象调用
C) 静态数据成员不能受private(私有)控制符的作用

D) 静态数据成员可以直接通过类名调用

二、编程题

551. 学生出勤记录 I - 力扣(LeetCode)

//C语言解法
bool checkRecord(char* s) {
    int absents = 0, lates = 0;
    int n = strlen(s);
    for (int i = 0; i < n; i++) {
        char c = s[i];
        if (c == 'A') {
            absents++;
            if (absents >= 2) {
                return false;
            }
        }
        if (c == 'L') {
            lates++;
            if (lates >= 3) {
                return false;
            }
        } else {
            lates = 0;
        }
    }
    return true;
}

482. 密钥格式化 - 力扣(LeetCode)

//C语言解法
char *licenseKeyFormatting(char *s, int k) {
    int lenS = strlen(s), lenChs = 0;
    char chs[lenS];
    for (int i = 0; i < lenS; ++i) {
        if (s[i] != '-')chs[lenChs++] = s[i]>='a'?s[i]-('a'-'A'):s[i];
    }
    char *res = calloc(lenChs / k + lenChs + 2,sizeof(char));
    int pos = 0;
    for (int i = 0; i < lenChs; ++i) {
        res[pos++] = chs[i];
        if ((i+1) % k == lenChs % k&&i<lenChs-1) {
            res[pos++] = '-';
        }
    }
    return res;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值