输入样例:
32*((2-2)+5)/(-15)
输出样例:
32
*
(
(
2
-
2
)
+
5
)
/
(
-15
)
知识点
- isdigit : 检查其参数是否为十进制数字字符
/* 找出字符串str中为阿拉伯数字0~9的字符*/
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
string str = "123@#FDsP[e?";
for(int i = 0; str[i] != 0; ++i)
{
if(isdigit(str[i]))
cout << str[i] << " is an digit character" <<endl;
}
return 0;
}
代码
#include<bits/stdc++.h>
//#include<ctype.h> 上一个包含了
using namespace std;
typedef long long ll;
int main(){
string s;
cin>>s;
ll len=s.size(),now=0;
while(now<len){
if(isdigit(s[now])){
while(isdigit(s[now])||s[now]=='.'){ //是数字 或者 是 .
putchar(s[now]);
now++; //因为要连续输出 数字 所以 while
}
puts(""); //输出字符串并换行 ; 此处就是换行
}else{
putchar(s[now]);
if(!( ((s[now]=='+'||s[now]=='-')&&isdigit(s[now+1])) && (s[now-1]=='('||now==0) )) //如果!里面的成立就不换行
{
puts("");
}
now++;
}
}
}
测试点
1 s[now]= =’.’
24 (s[now]= =’+’||s[now]= =’-’)&&now==0 满足则不换行 +2 -2
3 (s[now]= =’+’||s[now]= =’-’)&&s[now-1]= =’(’ (+2