[Ybt] [String processing class example 1] Number flip

Digital flip

Topic link: digital flip


Title description

Insert picture description here

Problem solving ideas

Determine whether the number is negative.

Remove leading 0 00

code

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int ok;
char c[11];

int main()
{
    
    
	cin>>c;
	if(c[0]=='-')
	{
    
    
		printf("-");
		int i=strlen(c)-1;
		while(c[i]=='0') i--;
		for(;i>0;i--)
			cout<<c[i];
	}
	else
	{
    
    
		int i=strlen(c)-1;
		while(c[i]=='0') i--;
		for(;i>=0;i--)
			cout<<c[i];
	}
}

Guess you like

Origin blog.csdn.net/SSL_guyixin/article/details/112985941