华为机试—数字逆序且求个位数乘积

时间:2015-01-05 00:33:33   收藏:0   阅读:225

技术分享


#include <iostream>
#include <string>
using namespace std;

//逆序
string revs(string s){
	int j = s.length()-1;
    int i=0;
	char t;
	while(i<j){
		t = s[i];
		s[i++]=s[j];
		s[j--]=t;
	}
	return s;
}

//个位乘积
int chen(string s){
	int ans =1;
	for(int i=0;i<s.length();i++){
		ans = ans*(s[i]-'0');
	}
	return ans;
}

int main()
{
	string s;
	cin>>s;
	string ss = revs(s);
	int n=chen(s);
	cout<<ss<<" "<<n<<endl;

	return 0;
}

技术分享



原文:http://blog.csdn.net/wtyvhreal/article/details/42409149

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!