整型反序

來源:互聯網
上載者:User

標籤:華為上機題

簡要描述:給出一個不多於5位的整數, 進行反序處理

要求:

1、求出它是幾位元

2、分別輸出每一位元字

3、按逆序輸出各位元字,例如原數為321,應輸出123(僅數字間以空格間隔, 負號與數字之間不需要間隔)

 

例如:輸入:12345

  輸出:5

1 2 3 4 5

54321

 

注意:如果是負數,負號加在第一個數字之前, 與數字沒有空格間隔

比如

       輸入:-12345

       輸出:5

-1 2 3 4 5

-54321

 

 

函數原型:

/*
輸入:
 iInput: 位元不大於5的整數

輸出:
 iNum:   整數位元 
 strRst: 空格間隔輸出結果
 iOutput:逆序整數

返回:
 0  成功
 -1 輸入無效
*/

int ProcessX(int iInput, int& iNum, char * strRst, int& iOutput) 

#include <stdlib.h>#include "oj.h"/*功能:給出一個不多於5位的整數,要求:1、求出它是幾位元 2、分別輸出每一位元字 3、按逆序輸出各位元字,例如原數為321,應輸出123輸入:整型 iInput,位元不大於5的整數輸出:    整數位元iNum空格間隔輸出結果    strRst逆序整數iOutput返回:0  成功-1 輸入無效*/int ProcessX(int iInput, int& iNum, char * strRst, int& iOutput){    if(iInput>99999||iInput<-99999)return -1;iNum=0;iOutput=0;    int temp=0;    //輸入為0if(iInput==0) {   iNum=1;       strRst[0]='0';   strRst[1]='\0';   iOutput=0; } else if(iInput>0) {    int temp=iInput;       while(temp>0)    {     iOutput=iOutput*10+temp%10;         iNum++;     temp=temp/10;     }    int t=0;  temp=iOutput; while(temp>0) {   strRst[t++]=temp%10+'0';   strRst[t++]=' ';   temp=temp/10; } strRst[--t]='\0'; } else if(iInput<0){iInput=-iInput; int temp=iInput;  while(temp>0)  {   iOutput=iOutput*10+temp%10;       iNum++;   temp=temp/10;  }  iOutput=-iOutput;   int t=1;  temp=-iOutput; strRst[0]='-'; while(temp>0) {   strRst[t++]=temp%10+'0';   strRst[t++]=' ';      temp=temp/10; }strRst[--t]='\0';}return 0;}






著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

整型反序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.