首页 > 其他 > 详细

1134: 字符串转换

时间:2018-04-21 16:39:57      阅读:362      评论:0      收藏:0      [点我收藏+]

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 ; 
}

 

1134: 字符串转换

原文:https://www.cnblogs.com/yi-ye-zhi-qiu/p/8901877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!