字符串练习题
来源:互联网 发布:淘宝投诉处理流程 编辑:程序博客网 时间:2024/06/05 07:35
1.请编写一个C函数,该函数可以实现将一个整数转为任意进制的字符串输出#include<stdio.h> #include<string.h> char ch[16] = {'0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f'}; //函数声明:将整数转换为任意进制的字符串 charchar *int2sys(int num,int n,int move_bit); int main() { int num; int n; int move_bit = 0; printf("Please input the num:\n"); scanf("%d",&num); printf("Please input the system(2,8,16):\n"); scanf("%d",&n); if(n == 2) { move_bit = 1; } else if(n == 8) { move_bit = 3; } else { move_bit = 4; } charchar *result = int2sys(num,n,move_bit); printf("%d的%d进制为%s\n",num,n,result); return 0; } charchar *int2sys(int num,int n,int move_bit) { int i = 0; int temp = 1; int len = 0; char temp_ch; static char result[33] = {0}; while(num != 0) { temp = num & (n - 1); result[i] = ch[temp]; num = num >> move_bit; i++; } len = strlen(result); for(i = 0; i < len / 2; i++) { temp_ch = result[i]; result[i] = result[len - 1 - i]; result[len - 1 - i] = temp_ch; } return result; }
2.输入一个字符串,计算字符串中子串出现的次数[objc] view plain copy print?在CODE上查看代码片派生到我的代码片#include<stdio.h> #include<string.h> #define MAX_SIZE 1024 int count_child_str(char* p_str,charchar *c_str) { int len = 0; int count = 0; len = strlen(c_str); while(*p_str != '\0') { if(strncmp(p_str,c_str,len) == 0) { count = count + 1; } p_str++; } return count; } int main() { int count; char p_str[MAX_SIZE] = {0}; char c_str[MAX_SIZE] = {0}; printf("Please input parent str:"); scanf("%s",p_str); printf("\nPlease input child str:"); scanf("%s",c_str); count = count_child_str(p_str,c_str); printf("count = %d\n",count); return 0; }
0 0
- 字符串练习题
- 字符串练习题
- 字符串练习题
- 字符串练习题
- 一道字符串的练习题
- 字符串练习题一
- 【练习题】压缩字符串
- 【练习题】28.字符串转换
- 【练习题】26.字符串压缩
- C字符串练习题心得
- 字符串-《数据结构1000》-练习题
- 字符串空格替换练习题
- 字符串算法练习题一
- [牛客]字符串移位练习题
- Python字符串练习题
- 字符串8:字符串移位练习题
- 关于字符串的几个练习题
- 华为上机练习题--压缩字符串
- POJ NOI0105-39 与7无关的数(Bailian2701)
- NSMutableArray与NSMutableIndexSet结合删除NSMutableArray中符合条件的object
- LeetCode 19. Remove Nth Node From End of List
- python爬取彩票网站开奖号码
- 文件上传与下载
- 字符串练习题
- 初窥Linux 之 文件权限
- 关于ThinkPHP下使用Uploadify插件提示HTTP Error (302)错误的解决办法
- C# static详解
- POJ 1837 Balance
- 11、Anaconda 快速入门
- maven nexus配置文件的作用
- HTML5 Canvas 旋转的“金字塔”
- 运行提示:WebDriverException: Message: 'geckodriver' executable needs to be in PATH.