wrong code

XDU 1060
#include <cstdio>
#include <iostream>
#include <stack>

using namespace std;

stack<int> m1;
stack<int> m2;
int main()
{
    string s;
    while(cin >> s)
    {
        int len  = s.size(), i;
        if(len == 1)
        {
            cout << "0.0";
            int r = s[0] - '0';
            r = r >= 5? 1: 0;
            cout << r << endl;
        }
        else if(len == 2)
        {
            cout << "0.";
            for(i = 0; i < len-1; i++)
            {
                m1.push(s[i]-'0');
            }
            int r = s[i] - '0';
            r >= 5? r = 1: r = 0;
            while(!m1.empty())
            {
                r += m1.top();
                m2.push(r%10);
                m1.pop();
                r /= 10;
            }
            if(r)
                m2.push(r);
            if(m2.size() == 2)
            {
                cout << m2.top();   m2.pop();
                cout << m2.top();   m2.pop();
            }
            else
            {
                cout << 0 << m2.top();
                m2.pop();
            }
            cout << endl;
        }
        else if(len == 3)
        {
            cout << "0.";
            for(i = 0; i < len-1; i++)
            {
                m1.push(s[i]-'0');
            }
            int r = s[i] - '0';
            r >= 5? r = 1: r = 0;
            while(!m1.empty())
            {
                r += m1.top();
                m2.push(r%10);
                m1.pop();
                r /= 10;
            }
            if(r)
                m2.push(r);
            cout << m2.top();   m2.pop();
            cout << m2.top();   m2.pop();
            cout << endl;
        }
        else
        {
            for(i = 0; i < len-1; i++)
            {
                m1.push(s[i]-'0');
            }
            int r = s[i] - '0';
            r >= 5? r = 1: r = 0;
            while(!m1.empty())
            {
                r += m1.top();
                m2.push(r%10);
                m1.pop();
                r /= 10;
            }
            if(r)
                m2.push(r);
            int m_len = m2.size();
            for(int i = 1; i <= m_len-2; i++)
            {
                cout << m2.top();
                m2.pop();
            }
            cout << '.';
            while(!m2.empty())
            {
                cout << m2.top();
                m2.pop();
            }
            cout << endl;
        }


    }
    
}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页