【YbtOJ高效进阶 字符串-1】【Luogu P1307】数字反转

链接

Luogu P1307
YbtOJ高效进阶 字符串-1

题目描述

在这里插入图片描述

样例输入#1

123

样例输出#1

321

样例输入#2

-830

样例输出#2

-38

思路

直接读入然后判断一下,倒着输出就好了,毕竟

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int t, b;
char c[100005];

int main()
{
    
    
	c[++t] = getchar();
	if(c[t] == '-') b = 1, c[t] = getchar();
	while(c[t] != '\n') c[++t] = getchar();
	t--; 
	while(c[t] == '0') t--;
	if(b) printf("-");
	for(int i = t; i >= 1; --i)
		printf("%c", c[i]);
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/LTH060226/article/details/113096529