PAT 乙级 1086 就不告诉你(15 分)---【数组反转】

在这里插入图片描述

思路:

1.利用数组反转函数,将int转化为string(to_string
2.reverse(s.begin(),s.end())反转,s.end()是最后一位的下一位
3.再将string(stoi())转化为int型输出

注意:

最后输出是数字!

代码:

#include<bits/stdc++.h>
using namespace std;

int main(){
    
    
	int a,b;
	cin>>a>>b;
	int c=a*b;
	
	//int->string
	string s = to_string(c);
	//反转
	reverse(s.begin(),s.end()); 
	int d = stoi(s);
	cout<<d;
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44926962/article/details/110203619
今日推荐