1221 Problem N- nasty decimal point - the entry title - string handling -C ++ to achieve

Question N: I hate the decimal point

Time limit: 1 Sec Memory Limit: 32 MB
submitted: 311 solved: 89

Title Description

Xiao Ming always hated the decimal point, a decimal point to see a headache. Unfortunately, the red gave him a topic, and asked him:
to give you a decimal x, what can you calculate the decimal point after the first n bits, right? (1 <= n <= 6 )
after Xiaoming see this problem, headache instantly fainted, can you help him?

Entry

: A first input t, t sets of data expressed, followed by t rows
per line decimal (input data in the form of ab is guaranteed, in order to simplify the problem, there is no case where the recurring decimal),
Then with a n, the decimal point the first of several.

Export

Bit n number of output after a decimal point number.

Sample input  Copy

3
1.234 1
2.345 2
3.456 3

Sample output  Copy

2
4
6

Code

Tip: To consider the case of output 0

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int T;
    scanf("%d",&T);
    getchar();
    string s;
    int num;
    for(int i = 0;i < T;i++){
        cin>>s;
        getchar();
        cin>>num;
        getchar();
        int j;
        int len=s.size();
        if(num>=1&&num<=6){
                for(j = 0;;j++){
                    if(s[j]=='.'){
                        break;
                    }
                }
                if((len-(j+1))<num){
                    printf("%d\n",0);
                }
                else{
                    printf("%d\n",s[j+num]-'0');
                }

        }else{
            i--;
            continue;
        }
    }
}

 

Published 20 original articles · won praise 0 · Views 121

Guess you like

Origin blog.csdn.net/weixin_31789689/article/details/104736254