蓝桥杯 算法训练 反置数

一直在敲java,在C++里敲string老是大写也是醉了,,

然后最近刷了一些小题目,但是为什么发这题,因为这题有些点记住

对于我们写其他的设计string与int的转换的题目有帮助

要点都下载下面代码的注释里了在这就不赘述了


ac代码


#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdlib>
using namespace std;

int convert(string as){
	//algorithm里的reverse算法 
	reverse(as.begin(),as.end());
	//使用库函数完成string转换成int 
	//使用前包含头文件 #include <cstdlib>
	int ai = atoi(as.c_str());
}

int sum(string a,string b){
	return convert(a)+convert(b);
}


int main()
{
	string a,b;
	cin>>a>>b;
	int sumi = sum(a,b);
	
	//使用流对象完成int转string,使用前包含头文件
	//#include <sstream> 
	stringstream ss;
	ss<<sumi;
	string str = ss.str();
	
	cout<<convert(str);
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/qq_36783389/article/details/80376164
今日推荐