P1553 Digital Inversion (upgraded version)

Source: Internet
Author: User

https://www.luogu.org/problem/show?pid=1553
Title Description

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 format:
A number S

Output format:
A number, that is, the number of reversals of s

Input/Output sample

Input Sample # #:

5087462
Ii
600.084

700/27

8,670%
Sample # # of output:

2647805
Ii
6.48

7/72

768%
Description

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)

Say the feeling of doing this topic, the difficulty of the subject is not difficult, is the entry level of difficulty, but the pit is that the data points too much, too much detail, must pay attention to the leading 0 of the problem, the subject of the discussion of the situation of the idea, the code is longer, but easier to understand, if you do not understand the place
AC Code

#include <bits/stdc++.h> using namespace std;
Char a[100];
int k,t,i,j;
    int main () {gets (a);
    int L=strlen (a);
          for (i=0;i<l;i++) {if (a[i]== '. ')
          {k=1;t=i;break;
              } if (a[i]== '/') {k=2;t=i;break;
            } if (a[i]== '% ') {k=3;t=i;break;
          }} if (k==0) {for (i=l-1;i>=0&&a[i]== ' 0 '; i--);
                 if (i>=0) for (; i>=0;i--) cout<<a[i];
    else cout<< "0";
          } else if (k==1) {for (i=t-1;i>=0&&a[i]== ' 0 '; i--);
                 if (i>=0) for (; i>=0;i--) cout<<a[i];
                 else cout<< "0";
        cout<< ".";
          for (i=t+1;i<l&&a[i]== ' 0 '; i++);
  if (i<l) for (int j=l-1;j>=i;j--)               cout<<a[j];
    else cout<< "0";
          } else if (k==2) {for (i=t-1;i>=0&&a[i]== ' 0 '; i--);
                 if (i>=0) for (; i>=0;i--) cout<<a[i];
                 else cout<< "0";
        cout<< "/";
          for (i=l-1;i>=t+1&&a[i]== ' 0 '; i--);
                 if (i>=t+1) for (; i>=t+1;i--) cout<<a[i];
    else cout<< "0";
          } else {for (i=t-1;i>=0&&a[i]== ' 0 '; i--);
                 if (i>=0) for (; i>=0;i--) cout<<a[i];
                 else cout<< "0";
        cout<< "%";
          for (i=l-1;i>=t+1&&a[i]== ' 0 '; i--);
    if (i>=t+1) for (; i>=t+1;i--) cout<<a[i];

} return 0; }

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.