• 数组-01. 字符转换(15)


    本题要求提取一个字符串中的所有数字字符('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!='
    ')
        {
            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;
    }
  • 相关阅读:
    Spiral Matrix
    Merge Intervals
    Edit Distance
    Insertion Sort List
    Add Binary
    Partition List
    Binary Tree Postorder Traversal
    单向链表反转
    Facebook Hacker cup Qualification round Problem 1
    判断二叉树是否为平衡二叉树
  • 原文地址:https://www.cnblogs.com/ligen/p/4264971.html
Copyright © 2020-2023  润新知