当前位置:网站首页>找数字
找数字
2022-07-04 13:32:00 【Zaltana】
输入一个字符串(包含26个英文字母大小写及.空格,不含其他字符),把其中连续的数字作为一个整数,依次存放到- -个数组中,输出这些整数的和。
格式
输入格式:输入字符串
输出格式:输出整型
样例
输入: a123.456 jmk32kk
输出: 611
#include<bits/stdc++.h>
using namespace std;
int main( )
{
char a[100];
cin.getline(a,100);
int lens = strlen(a);
int sum=0, num=0;
for (int i=0; i<=lens; i++) {
int loc = a[i] - '0';
if (loc>=0 && loc<=9) {
num = num*10 + loc;
}
else {
sum += num;
num = 0;
}
}
printf("%d", sum);
return 0;
}
边栏推荐
猜你喜欢

Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)

Combined with case: the usage of the lowest API (processfunction) in Flink framework

开发中常见问题总结

Introduction to asynchronous task capability of function calculation - task trigger de duplication

如何配和弦

Ffmpeg Visual Studio development (IV): audio decoding

曝光一下阿里的工资待遇和职位级别

Preliminary exploration of flask: WSGI

Ffprobe common commands
![leetcode:6109. Number of people who know the secret [definition of DP]](/img/95/03e2606b249f26db052cf5075041c1.png)
leetcode:6109. Number of people who know the secret [definition of DP]
随机推荐
LVGL 8.2 Line wrap, recoloring and scrolling
No servers available for service: xxxx
LVGL 8.2 List
Guitar Pro 8win10最新版吉他学习 / 打谱 / 创作
leetcode:6109. Number of people who know the secret [definition of DP]
Luo Gu - some interesting questions 2
Docker compose public network deployment redis sentinel mode
Red envelope activity design in e-commerce system
为什么国产手机用户换下一部手机时,都选择了iPhone?
Flutter reports an error no mediaquery widget ancestor found
C language achievement management system for middle school students
Detailed explanation of visual studio debugging methods
Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)
How to build a technical team that will bring down the company?
Deep learning 7 transformer series instance segmentation mask2former
[C language] Pointer written test questions
LVGL 8.2 Line
【C语言】指针笔试题
LVGL 8.2 Sorting a List using up and down buttons
LeetCode 1200 最小绝对差[排序] HERODING的LeetCode之路