本题要求提取一个字符串中的所有数字字符('0'……'9'),将其转换为一个整数输出。

输入格式:

输入在一行中给出一个不超过80个字符且以回车结束的字符串。

输出格式:

在一行中输出转换后的整数。题目保证输出不超过长整型范围。

输入样例:

free82jeep5

输出样例:

825

跟0相关的要点,只有一个0,或者以0开头。
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <stdlib.h>

using namespace::std; 

int main(){
    
    char temp;
    scanf("%c",&temp);
    int flag=0;
    int count=0;
    while(temp!='\n')
    {
        if(temp<='9'&&temp>='0')
        {
            if(flag==1)
            {
                printf("%c",temp);    
            }else if(flag==0&&temp!='0')
            {
                flag=1;
                printf("%c",temp);
            }
            else{
                count++;
            }
            
        }
        
        scanf("%c",&temp);
    } 
    if(count!=0&&flag==0)
    {
            printf("0");
    }
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2021-11-30
  • 2021-07-24
  • 2022-03-05
相关资源
相似解决方案