Luogu Exam Bank—Introduction 1—Order Structure—P5705 [Deep Foundation 2. Example 7] Number Reversal

1. Topic requirements

 

Two, the code

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	//输入
	double num1;	
	cin >> num1;
	
	//转字符串
	string str1 = to_string(num1);
	int len = str1.length();
	
	//分切为字符数组
	char ch1[len];	
	strcpy(ch1,str1.c_str());
	
	//反序
	char ch2[len];
	for(int i=0;i<len;i++)
		{
			ch2[len-1-i] = ch1[i];
		}
		
	//转字符串
	string str2 = ch2;
	
	//转浮点数
	double num2 = stod(str2);
	
	//打印
	cout << num2;
	
	return 0;	
}

Guess you like

Origin blog.csdn.net/ssismm/article/details/128494395