日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

zzuli oj 1167逆转数(指针专题)

發(fā)布時間:2025/5/22 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 zzuli oj 1167逆转数(指针专题) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Description

  任意給你一個整數(shù),這個數(shù)可能很大(最長不超過100位),你能求出它的逆轉(zhuǎn)數(shù)嗎??
  逆轉(zhuǎn)數(shù)定義如下:?
  1.一個末尾沒有0的整數(shù),它的逆轉(zhuǎn)數(shù)就是各位數(shù)字逆序輸出;?
  2.一個負數(shù)的逆轉(zhuǎn)數(shù)仍是負數(shù);?
  3.一個末尾有0的整數(shù),它的逆轉(zhuǎn)數(shù)如同下例:?
  reverse (1200) = 2100?
  reverse (-56) = -65?
  要求定義并使用如下函數(shù):?
  void reverse(char *str)?
  {?
  //函數(shù)求出str的逆轉(zhuǎn)數(shù)并存入str。?
  }?

Input

  輸入一個長整數(shù)str,不超過100位,輸入的整數(shù)不含前導0。

Output

  輸出str的逆轉(zhuǎn)數(shù)。輸出占一行。

Sample Input

  -123456789000

Sample Output

  -987654321000 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 7 int main(int argc, char** argv) 8 { 9 char str[101]; 10 int i,flag=0,count=0; 11 gets(str); 12 /*輸出負號*/ 13 if(str[0]=='-') 14 printf("-"); 15 /*倒序輸出*/ 16 for(i=strlen(str)-1;i>=1;i--) 17 { 18 if(str[i]=='0'&&flag==0) 19 { 20 count++;//用來計數(shù)0的個數(shù) 21 continue;//跳過 22 } 23 if(str[i]!='0'||flag!=0) 24 { 25 printf("%c",str[i]); 26 flag=1;//標記尾數(shù)是否為0 27 } 28 29 } 30 if(str[0]!='-') 31 printf("%c",str[0]);//最后輸出第一個數(shù) 32 /*輸出前面跳過的0*/ 33 for(i=1;i<=count;i++) 34 printf("0"); 35 return 0; 36 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/millerchan/p/5059783.html

總結(jié)

以上是生活随笔為你收集整理的zzuli oj 1167逆转数(指针专题)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。