Keyboard Row
来源:互联网 发布:南京行知基地卫生间 编辑:程序博客网 时间:2024/05/16 19:33
#include <stdio.h>#include <string.h>//字符串1是否包含字符串2,在同一行int inStr(char *str1, char *str2){ int i, j, str1len = strlen(str1), str2len = strlen(str2); int flag = str2len; int temp; for (i = 0; i < str2len; i++) { for (j = 0; j < str1len; j++) { temp = abs(str2[i] - str1[j]); if ((str2[i] == str1[j]) || temp==32) { flag--; break; } } } if (flag == 0) return 1; else return 0;}char** findWords(char** words, int wordsSize, int* returnSize) { char* keyBoardStr[] = { "qwertyuiop","asdfghjkl","zxcvbnm" }; char** result = (char**)malloc(wordsSize*sizeof(char*)); int i,flag; if (words == NULL) return NULL; for (i = 0; i<wordsSize; i++) result[i] = (char*)malloc(100 * sizeof(char)); for (i = 0; i < wordsSize; i++) { if (inStr(keyBoardStr[0], words[i])) flag = 1; else if (inStr(keyBoardStr[1], words[i])) flag = 1; else if (inStr(keyBoardStr[2], words[i])) flag = 1; if (flag == 1) { result[*returnSize] = words[i]; *returnSize += 1; } flag = 0; } return result;}void main() { char* input[4] = { "Hello", "Alaska", "Dad", "Peace" }; char** result = (char**)malloc(4 * sizeof(char*)); int len=0; result = findWords(input,4,&len); printf("%s\n", result[0]); printf("%s\n", result[1]); printf("%d\n", len); system("pause");}
阅读全文
0 0
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Keyboard Row
- Leetcode-500. Keyboard Row
- 【Leetcode】500. Keyboard Row
- 500. Keyboard Row
- leetcode-500-Keyboard Row
- 500. Keyboard Row
- 【LeetCode】500. Keyboard Row
- 500. Keyboard Row
- AdjustTokenPrivileges失败的解决方法
- 一些编程的规范
- Python练习12----lambda
- Linux:如何使用gdb调试多进程多线程程序
- (vue.js)vue-cli构建,scss文件引入本地css意外报错
- Keyboard Row
- Hive原理
- Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
- IT专业英语整理积累(1)
- Android Studio在创建项目是一直处于building “project name”gradle project info的解决办法
- CSS、JS中的相对路径引用
- KMP算法
- PHP面试总结-2
- 欧拉公式的推导