题解 洛谷 P1553

字符串入门题,读入一行字符,先将第一个数读入翻转,读入下一个字符(如果没有则退出),再将下一个数读入翻转

#include
#include
#include
#include
using namespace std;
void fan(unsigned long long n)
{
    if (n == 0) 
    {
        cout << 0;
        return;
    }
    while (n % 10 == 0) 
        n /= 10;
    while (n != 0)
    {
        cout << n % 10;
        n /= 10;
    }
}
int main()
{
    string s;
    cin >> s;
    stringstream ss(s);
    unsigned long long n;
    ss >> n;
    fan(n);
    char ch;
    if (ss >> ch)
    {
        if (ch == '.') 
        {
            cout << ".";
            unsigned long long t;
            ss >> t;
            fan(t);
        }
        if (ch == '/') 
        {
            cout << "/";
            unsigned long long t;
            ss >> t;
            fan(t);
        }
        if (ch == '%') 
        {
            cout << "%";
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/happyLittleRabbit/p/10305294.html

你可能感兴趣的:(题解 洛谷 P1553)