P5705 【深基2.例7】数字反转

https://www.luogu.com.cn/problem/P5705
在这里插入图片描述

  • 使用字符串,从最后往前输出
#include<iostream>
using namespace std;
int main()
{
    string a;
    cin >> a;
    for(int i = a.size()-1;i >= 0;i--)
        cout << a[i];
}

大佬

如果用scanf读入那么后面一定要加!=EOF,如下列合法程序:

while(scanf("%d",&n)!=EOF)
{

}

或者while(~scanf("%d",&n))

发布了372 篇原创文章 · 获赞 48 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/dghcs18/article/details/104308371