Amano_Hina @ 2022-02-26 21:22:58
我用的栈和字符串,为啥会RE
#include <bits/stdc++.h>
using namespace std;
int main()
{
stack <char> a;
string b;
cin>>b;
if(b.at(1)=='-')
{
cout<<"-";
}
for(int i=1;i<=b.size();i++)
{
if(b.at(1)=='-')
{
continue;
}else{
// char c;
a.push(b.at(i));
}
}
for(int i=1;i<=a.size();i++)
{
if(a.top()=='0')
{
continue;
}else{
cout<<a.top();
a.pop();
}
}
return 0;
}
by StillEmpty @ 2022-02-26 21:26:06
@Amano_Hina 因为string的下标是0
到str.size() - 1
,所以str.at(0)
才是字符串第一个字符,str[str.size() - 1]
是最后一个,str[str.size()]
会导致re
by Q__A__Q @ 2022-02-26 21:26:31