Rokua-Digital inversion (upgraded)-Simple string

Source: Internet
Author: User

Title DescriptionDescription given a number, invert the number on each bit to get a new number.
This is different from the first question in the NOIp2011 group: This number can be decimal, fractional, percent, integer. Integer inversion is the reversal of all digits, the fractional reversal is the number of integral parts of the reversal, and then the number of fractional part reversal, do not Exchange integer part and fractional part; The fractional reversal is the inverse of the denominator, and the number of the numerator is reversed, the numerator and denominator are not exchanged; The new number of integers should also satisfy the common form of integers, that is, unless the given original number is zero, the highest digit of the new number that is reversed should not be zero; the end of the new decimal number is not 0 (unless the fractional part has no other number except 0); The fractions are not numerator, the numerator and denominator are not decimals (numerator drop shoes Sorry, No, I can't. The input data guarantees that the denominator is not 0), this time there are no negative numbers. input/output format input/output Input Format:
A number S
output Format:
A number, that is, the number of reversals of s input and Output sample sample Input/output sample Test point # # Input Sample:


5087462
Ii
600.084

700/27

8,670%

Sample output:


2647805
Ii
6.48

7/72

768%

DescriptionDescription All data: 25%s is an integer, not greater than 20 bits
25%s is a decimal, and the integer and fractional parts are not greater than 10 bits
25%s are fractions, numerator and denominator are not greater than 10 bits
25%s is a percentage, the numerator is not greater than 19 bits
(20 data) Idea: This problem is a bit difficult, to be divided into categories to operate, to determine whether it is a percentage, fractional, integer, fractional operation. The code is as follows (this code from nine degrees OJ, the code is Pascal, can not understand):
1 varI,j,k,m,n,q,p:longint; 2 s:string; 3 procedureFZ1 (s:string);{This is the process of dealing with ordinary integers .}    4 begin    5   ifs[1]='0'  Then beginWrite'0'); exit;End;{for the answer is 0 the case of the treatment}    6j:=length (s); 7    whiles[j]='0'  DoDec (j);{go to 0}    8    forI:=jDownto 1  Do{the inverted output is the answer}    9     begin    Ten write (s[i]);  One     End;  A End;  - procedureFZ2 (s:string);{special handling for fractional parts of decimals}     - varI:longint;  the begin     -j:=length (s);  -   ifs[j]='0'  Then beginWrite'0'); exit;End;  -    whiles[j]='0'  DoDec (j);{Remove the beginning of the 0}     +k:=1;  -    whiles[k]='0'  DoInc (k);{Remove the end of the 0}     +    forI:=jDowntoK Do     A     begin     at write (s[i]);  -     End;  - End;  - begin     - read (s);  -n:=length (s);  inM:=pos ('.', s);  -   ifM>0  Then begin{If the data is a decimal, then the processing}     toFZ1 (copy (s),1, M-1));{The integer part of the decimal is processed}     +Write'.');{Play decimal points in the middle of the data}     -FZ2 (Copy (s,m+1, n));{The processing of fractional parts of the decimal point}     theExit{quit when you're done with it .}     *   End;  $P:=pos ('/', s);{The following treatment is roughly the same as the}    Panax Notoginseng   ifP>0  Then begin     -FZ1 (copy (s),1, P-1));  theWrite'/');  +FZ1 (Copy (s,p+1, N));  A exit;  the   End;  +Q:=pos ('%', s);  -   ifQ>0  Then begin     $FZ1 (copy (s),1, Q-1));{only one data is required for the data of the percent semicolon}     $Write'%');  - exit;  -   End;  theFZ1 (s);{If the data is not a decimal, a fraction, or a percentage, then the integer is processed directly}     - End.

Rokua-Digital inversion (upgraded)-Simple string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.