给出整数X和字符串S。 如果S[i]='I',对X加1.如果S[i]='D',对X减1。 求在加加减减的过程中,X的最大值和最小值分别是多少。 0 <= X <= 1000 字符串长度不超过100 输入格式 第1行:1个字符串,仅包含'I'和'D',长度不超过100 第2行:1个整数,表示X的初值,0 <= X <= 1000 输出格式 第1行:2个整数,分别表示在操作过程中的最大值和最小值
```c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[105];
int n,x,maxn,minx;
gets(a);
n=strlen(a);
cin>>x;
maxn=minx=x;
/*for(int i=0;i<n;i++)
cout<<a[i];
cout<<endl;*/
for(int i=0;i<n;i++)
{
if(a[i]=='I')
{
x++;
if(x>maxn)
maxn=x;
}
else
{
x--;
if(x<minx)
minx=x;
}
cout<<x<<endl;
}
cout<<maxn<<" "<<minx;
return 0;
}
```
调试了一下,没有报错啊
你出现什么错误呢?