1134: 字符串转换

1134: 字符串转换

时间限制: 1 Sec  内存限制: 128 MB
提交: 3284  解决: 1772
[提交][状态][讨论版][命题人:admin]

题目描述

输入一个以回车结束的字符串,它由数字和字母组成,请过滤掉所有非数字字符,然后将数字字符串转换成十进制整数后乘以2输出。

输入

输入一个以回车结束的字符串,长度不超过100,由数字和字母组成。

输出

将转换后的整数乘以2输出,测试数据保证结果在int范围内。

样例输入

sg987aa65t498

样例输出

197530996

#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std ; 


#define maxn 120 
char str[maxn] ; 
int num ; 
int result = 0 ; 

int main(){
    num = 0 ; 
    cin>>str ; 
    for(int i=0 ; i<strlen(str) ; i++){
        if(isdigit(str[i])){
            result = result * 10 + str[i] - '0' ; 
        }
    }

    cout<<result*2<<endl ; 
    return 0 ; 
}
原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/8901877.html