Topic Portal (internal title 87)
Input Format
Read data from files $ expression.in $ in.
Enter a row, a string $ S $, represents the original expression, guarantee the legitimate expression
Output Format
Output to a file in $ expression.out $.
A string that represents the result of an expression biggest sign to add a program.
answer
Sample input 1:
10+20-30
Sample output 1:
10+20-3+0
Sample input 2:
-3-4-1
Sample Output 2:
-3-4-1
Sample input 3:
-200+351-1600
Sample output 3:
-2+0+0+351-1+600
Data range and tips
Set the string length $ | S | $
to $ 30 \% $ data satisfies $ | S | \ leqslant 20 $
data for $ 50 \% $ meet integer expression in the $ 32 $-bit integer $ int $ range within
for $ 100 \% $ of data to meet the $ | S | \ leqslant 100,000 $
answer
Analog much to say, but would like to condemn the topic and people ......
Obviously $ + $ 0 $ and $ -0 is the same, why not write $ SPJ $?
Issued last character of the large sample is $ '+' $, $ KX $ amuse me do?
Time complexity: $ \ Theta (| S |) $.
Expectations score: $ 100 $ points.
Actual score: $ 100 $ points.
Code time
#include<bits/stdc++.h>
using namespace std;
int n;
char ch[100001];
int main()
{
scanf("%s",ch+1);
n=strlen(ch+1);
for(int i=1;i<=n;i++)
{
putchar(ch[i]);
if(ch[i]=='-')
{
putchar(ch[i+1]);
if(i+1==n)return 0;
for(int j=i+2;j<=n;j++)
{
if(ch[j]=='+'||ch[j]=='-')
{
i=j-1;
break;
}
putchar('+');
if(ch[j]!='0')
{
i=j-1;
break;
}
putchar(ch[j]);
if(j==n)return 0;
}
}
}
return 0;
}
rp ++