字符串中存在的数字的个数
来源:互联网 发布:微信 python创建菜单 编辑:程序博客网 时间:2024/06/18 05:05
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void take_num(const char *strIn, int *n, unsigned int *outArray)
{
int tmp=0;
int count=0;
int flag=0;
while(*strIn!=NULL)
{ if(*strIn<='9'&&*strIn>='0')//字符型强制转换为int,-48即可
{
tmp*=10;
tmp+=(int)*strIn-48;//tmp+=*strIn-'0';
flag=1;
}
else if(flag==1)//更多的是标志位的技巧使用
{
flag=0;
outArray[count]=tmp;
tmp=0;
count++;
}
strIn++;
}
*n=count;
}
int main()
{
const char strIn[]="bd45dfvd2sew6wfe9e44wefwe777scs1.059cw4";
int n;
unsigned int outArray[100];
take_num(strIn, &n, outArray);
printf("字符串中存在的数字的个数为%d:\n",n);
for(int i=0;i<n;i++)
printf("%d",outArray[i]);
printf("\n");
getch(); /*从键盘读取一个字符,但不显示于屏幕*/
return 0;
}
#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void take_num(const char *strIn, int *n, unsigned int *outArray)
{
int tmp=0;
int count=0;
int flag=0;
while(*strIn!=NULL)
{ if(*strIn<='9'&&*strIn>='0')//字符型强制转换为int,-48即可
{
tmp*=10;
tmp+=(int)*strIn-48;//tmp+=*strIn-'0';
flag=1;
}
else if(flag==1)//更多的是标志位的技巧使用
{
flag=0;
outArray[count]=tmp;
tmp=0;
count++;
}
strIn++;
}
*n=count;
}
int main()
{
const char strIn[]="bd45dfvd2sew6wfe9e44wefwe777scs1.059cw4";
int n;
unsigned int outArray[100];
take_num(strIn, &n, outArray);
printf("字符串中存在的数字的个数为%d:\n",n);
for(int i=0;i<n;i++)
printf("%d",outArray[i]);
printf("\n");
getch(); /*从键盘读取一个字符,但不显示于屏幕*/
return 0;
}
0 0
- 字符串中存在的数字的个数
- 字符串旋转&数字中1的个数
- 统计一个字符串中数字的个数
- 一个字符串中找字幕,数字,空格,和其他的个数,并分别存在num[4]中(指针法)
- 字符串分类,输出字符串中字母,数字,符号的个数
- 输入一段字符,判断字符串中字母的个数,数字的个数和其他字符个数
- 字符串中大小写英文及数字的个数
- 统计字符串中每个字母以及数字的个数!
- 16周:统计字符串中数字、字母出现的个数。
- c++builder统计一个字符串中数字的个数
- 统计已知字符串str中数字的个数
- java统计一个字符串中中文,英文,数字的个数
- 黑马程序员--OC统计字符串中数字个数的方法
- 杭电acm 2017统计字符串中数字的个数
- 统计一个字符串中数字,空格,字母的个数!
- 查询字符串中字母和数字的个数
- c++builder统计一个字符串中数字的个数
- 求出字符串中大写字母,小写字母和数字的个数
- Windows操作系统产品名与内部版本号的对应
- mysql5.6免安装配置
- 140722暑期培训
- 通往5G之路的常见问题
- ASP:LinkButton控件(按钮类型控件)
- 字符串中存在的数字的个数
- GetVersionEx 获取系统版本信息
- eclipse建包的一些细节
- 字符串中提取数字
- 【搜索-DFS】N皇后问题
- 不要小看了get 与set
- font
- 字符串中最大的回文长度
- STM32开发指南笔记(硬件篇)