网站建设有哪些岗位职责,新乡网站建设哪家专业,wordpress 系统,河南注册公司代理字符串在C语言中我感觉还是比较难的#xff0c;主要是C中没有String#xff0c;只能使用字符数组来创建字符串。这个就有点难受了
第一题 LCR 122. 路径加密
https://leetcode.cn/problems/ti-huan-kong-ge-lcof/description/ 第一题本来是力扣05的一道题#xff0c;但是变…字符串在C语言中我感觉还是比较难的主要是C中没有String只能使用字符数组来创建字符串。这个就有点难受了
第一题 LCR 122. 路径加密
https://leetcode.cn/problems/ti-huan-kong-ge-lcof/description/ 第一题本来是力扣05的一道题但是变题了。 不过我感觉变的这个还比较简单了不需要创建多余的空间一对一替换就可以了。 思路很简单遍历字符遇到.就替换为空格如果是其他的就原样输出这个最烦的是每个结尾必须加‘\0’确实有点难受
char* pathEncryption(char* path) {int len strlen(path);char *res (char *)malloc(sizeof(char) * len 1);int index 0;for(int i 0; i len; i) {if(path[i] .) {res[index] ;}else {res[index] path[i];}}res[index] \0;return res;
}第二题 1876. 长度为三且各字符不同的子字符串
https://leetcode.cn/problems/substrings-of-size-three-with-distinct-characters/description/ 遍历数组每三个字符进行一次比较看他们是否互相相等否则结果数1
int countGoodSubstrings(char* s) {int len strlen(s);int res 0;for(int i 0; i len - 2; i) {char a s[i];char b s[i 1];char c s[i 2];if(a ! b b ! c a ! c) {res;}}return res;
}第三题 LCP 17. 速算机器人
https://leetcode.cn/problems/nGK0Fy/description/ 给你一个x和y的初始值然后给一个字符串这个字符串中只有大写A和B对应的A和B有x和y的计算方法根据字母的顺序进行运算最后将xy即可 这一题我出现了两个错误: 1、C语言中字符必须用‘’单引号 2、如果非全局使用变量直接在局部定义即可 所以基础还是非常重要的
int calculate(char* s){int len strlen(s);int x 1;int y 0;for(int i 0; i len; i) {if(s[i] A) {x 2 * x y;}else if(s[i] B) {y 2 * y x;}}return x y;
}第四题 2011. 执行操作后的变量值
https://leetcode.cn/problems/final-value-of-variable-after-performing-operations/description/
int finalValueAfterOperations(char** operations, int operationsSize) {int x 0;for(int i 0; i operationsSize; i) {if(operations[i][1] -) --x;else x;}return x;
}