c++求助

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

66666
by LIUYIFAN5 @ 2023-11-18 08:37:12


``` #include<iostream> using namespace std; int main() { double p; int i,a,b,c,d; cin>>p; i=int(p*10); a=i/1000; b=i/100%10; c=i/10%10; d=i%10; cout<<d<<"."<<c<<b<<a; } ```
by LIUYIFAN5 @ 2023-11-18 08:38:01


````cpp #include <bits/stdc++.h> using namespace std; int main(){ string a; cin>>a; for(int i=0,j=a.length()-1;i<=a.length()/2;i++,j--) swap(a[i],a[j]); cout<<a; return 0; } ``````
by gaojizhe05 @ 2023-11-18 08:39:16


可以用四个数字啊,因为题目中说了输入的数是不小于100不大于1000所以是1000>x>=100的吧 所以可以这样写 核心代码: ``` char a, b, c, d;//用char来读 scanf("%c%c%c.%c", &a, &b, &c, &d);//读入一下每一位,中间有个小数点 printf("%c.%c%c%c", d, c, b, a);//反向输出 return 0; ```
by char_cha_ch_ @ 2023-11-18 08:43:35


这种题为什么不自己想想,
by FreedomKing @ 2023-11-18 09:12:22


为什么不能当作普通的反转字符串题来做呢? ```cpp #include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); string str; cin >> str; reverse(str.begin(), str.end()); cout << str << '\n'; return 0; } ```
by SR_star @ 2023-11-25 22:37:01


|