全WAAAAA 求助大佬

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

界内嘻哈 @ 2020-05-11 17:28:49

我把gets( )换成了getline( )
咋还不对啊
#include<bits/stdc++.h>
using namespace std;

int main(void)
{
    string str;
    int i;
    getline(cin,str);
    for(i=str.length()-1; i >= 0; i--)
    {
        printf("%c", str[i]);
    }   
    return 0;
}

by 界内嘻哈 @ 2020-05-11 17:47:24

@蒟蒻跟风侠 我运行报错了


by 界内嘻哈 @ 2020-05-11 17:48:04

@蒟蒻跟风侠 你发的这个


by SIXIANG32 @ 2020-05-11 17:48:14

@界内嘻哈 reverse不香吗?


by 界内嘻哈 @ 2020-05-11 17:48:31

@蒟蒻跟风侠 啊哈哈哈


by SIXIANG32 @ 2020-05-11 17:49:43

@界内嘻哈

#include<iostream>
#include<string>
#include<sstream>
using namespace std;
stringstream temp1,temp2; 
int main()
{
    unsigned long long a,b,na=0,nb=0;
    string str,strson1,strson2;
    string   _strson1,_strson2;
    cin>>str;
    if(str.find("/")!=string::npos)
    {
        strson1=str.substr(0,str.find("/"));
        strson2=str.substr(str.find("/")+1,str.size()-1);
        temp1<<strson1;
        temp1>>a;
        temp2<<strson2;
        temp2>>b;
        for(;a!=0;a/=10)na=na*10+a%10;
        for(;b!=0;b/=10)nb=nb*10+b%10;
        cout<<na<<'/'<<nb<<endl;
        return 0;
    }
    if(str.find(".")!=string::npos)
    {
        strson1=str.substr(0,str.find("."));
        strson2=str.substr(str.find(".")+1,str.size()-1);
        temp1<<strson1;
        temp1>>a;
        temp2<<strson2;
        temp2>>b;
        for(;a!=0;a/=10)na=na*10+a%10;
        for(;b!=0;b/=10)nb=nb*10+b%10;
        while(b%10!=0)b/=10;
        cout<<nb<<'.'<<na<<endl;
        return 0;
    }
    if(str.find("%")!=string::npos)
    {
        strson1=str.substr(0,str.size()-1);
        temp1<<strson1;
        temp1>>a;
        for(;a!=0;a/=10)na=na*10+a%10;
        cout<<na<<'%'<<endl;
        return 0;
    }
    temp1<<str;
    temp1>>a; 
    for(;a!=0;a/=10)na=na*10+a%10;
    cout<<na<<endl;
}

一个不是秘密的秘密:数字反转二可以AC这道题……


by Surelysuper @ 2020-05-11 17:49:57

@界内嘻哈

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int l=a.size();
    for(int i=l-1;i>=0;i--)
    cout<<a[i];
    return 0;
}

by 界内嘻哈 @ 2020-05-11 17:56:25

@SIXIANG 这个花里胡哨,还没reverse好,哈哈哈哈


by 界内嘻哈 @ 2020-05-11 17:56:40

@蒟蒻跟风侠 谢谢大佬


by liqingyang @ 2020-05-11 17:59:07

@界内嘻哈 哈哈哈哈


by 小小藤藤蛇 @ 2020-05-11 18:13:23

为什么这个帖一堆哈哈哈啊...


上一页 | 下一页