CodeForces 697B Barnicle 和 Codeforce 691 C Puzzles 科学计数法的正逆互推 CodeForces 691B 一个对称的小题;

来源:互联网 发布:淘宝企业店能注销吗 编辑:程序博客网 时间:2024/04/24 23:57

Codeforce 697B Barnicle 题目链接, click here.
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.

这里写图片描述

Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it’s a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.
Barney doesn’t know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.

Input
The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character ‘e’ (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value.
a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.

Output
Print the only real number x (the desired distance value) in the only line in its decimal notation.
Thus if x is an integer, print it’s integer value without decimal part and decimal point and without leading zeroes.
Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).

Examples

input
8.549e2
output
854.9

input
8.549e3
output
8549

input
0.33e0
output
0.33

题意:给一个科学计数法的数,让你转化为十进制的数.注意:题目中Input中加粗的部分是需要注意的.1> b,d没有后导零;2> a如果等于0,b一定等于0;
#include<stdio.h>#include<string>#include<string.h>using namespace std;int main(){    char s[200];    memset(s,0,sizeof(0));    scanf("%s",s);    int zero_d=0,dd=0;    int l=strlen(s), a , num[109] , b=0;    int e;//记录e的位置;    a=s[0]-'0';//a;    for(int i=2; i<l; i++)    {        if(s[i]=='e')        {            e=i;            break;        }        if(s[i]=='0')            zero_d++;//0的个数;        else            dd++;//不是0的个数;    }    int f=1;    for(int i=l-1; i>e; i--)    {        b+=(s[i]-'0')*f;//b        f*=10;    }    if(a==0&&b==0)//a,b都是0的情况;    {        if(zero_d==e-2)//d中全是0;            printf("0");        else            for(int i=0; i<e; i++)                printf("%c",s[i]);    }    else if(b==0&&a!=0)//b是0,a不是0;    {        if(zero_d==e-2)//d 全是0;            printf("%d",a);        else        {            for(int i=0; i<e; i++)                printf("%c",s[i]);        }    }    else if(a!=0&&b!=0)//同时不为0;    {        if(e-2<b)//b超过d的长度;        {            b-=e-2;//b代表的是此时d的长度;            printf("%d",a);            for(int i=2; i<e; i++)                printf("%c",s[i]);            for(int i=1; i<=b; i++)                printf("0");        }        else        {            printf("%d",a);            for(int i=2; i<=b+1; i++)                printf("%c",s[i]);            if(e-2!=b)//d的长度不等于b要求向后推的长度;            {                printf(".");                for(int i=b+2; i<e; i++)                    printf("%c",s[i]);            }        }    }    return 0;}

Codeforce 691 C Exponential notation,题目链接, click here!!!
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u

Submit

Status

Practice

CodeForces 691C

Description

You are given a positive decimal number x.

Your task is to convert it to the “simple exponential notation”.

Let x = a·10b, where 1 ≤ a < 10, then in general case the “simple exponential notation” looks like “aEb”. If b equals to zero, the part “Eb” should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b.

Input

The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can’t use standard built-in data types “float”, “double” and other.

Output

Print the only line — the “simple exponential notation” of the given number x.

Sample Input

Input
16

Output
1.6E1

Input
01.23400

Output
1.234

Input
.100

Output
1E-1

Input
100.

Output
1E2
题意很简单,但是状态有点多...明天写…粘上代码先…

#include<bits/stdc++.h>using namespace std;const int maxn = 1000000;char s[maxn];int main(){    scanf("%s",s);    int l=strlen(s),point=-1;    int a=0,b=l,ans=0;    //get rid of leading zeros and trailing zeros ;    for(int i=0; i<l; i++)        if(s[i]!='0'&&s[i]!='.')        {            a=i;            break;        }    for(int i=l-1; i>=0; i--)        if(s[i]!='0'&&s[i]!='.')        {            b=i;            break;        }    for(int i=0; i<l; i++)        if(s[i]=='.')        {            point=i;            break;        }//printf("point   %d,,a %d, ,,b %d\n",point ,a,b);    if(point==-1)  //indicate that the numb is integer;    {        printf("%c",s[a]);        if(a!=b)        {            printf(".");            for(int i=a+1; i<=b; i++)                printf("%c", s[i]);            printf("E%d",l-a-1);        }        else        {            if(l!=a+1)                printf("E%d",l-a-1);        }    }    else if(point==0)    {        printf("%c",s[a]);        if(a!=b)            printf(".");        for(int i=a+1; i<=b; i++)            printf("%c",s[i]);        printf("E-%d",a);    }    else    {        printf("%c",s[a]);        if(point>a)        {            if(b<point)//如果 b 在point 的左边;            {                if(a==b)                {                    if((point-a-1))                        printf("E%d",point-a-1);                }                else                {                    printf(".");                    for(int i=a+1; i<=b; i++ )                        printf("%c",s[i]);                    printf("E%d",point-a-1);                }            }            else            {                printf(".");                for(int i=a+1; i<=b; i++)                    if(s[i]!='.')                        printf("%c",s[i]);                if((point-a)!=1)                    printf("E%d",point-a-1);            }        }        else        {            if(a!=b)                printf(".");            for(int i=a+1; i<=b; i++)                printf("%c",s[i]);            printf("E-%d",a-point);        }    }    return 0;}

CodeForces 691B Puzzles 题目链接, click here!!!!!!!!

这里写图片描述
这个图中,能够左右对称的有15个,包括以下:
A,H,I,M,T,Y,U, O,o,V,v,W,w,X,x;(m不算)
能够左右对称的有两组:p和q, b和d;
这样一来就好做了...

#include<bits/stdc++.h>using namespace std;const int maxn = 1008;char s[maxn];int main(){    scanf("%s",s);    int l=strlen(s);    char str[20];    str[0]='A';    str[1]='H';    str[2]='v';    str[3]='I';    str[4]='M';    str[5]='O';    str[6]='o';    str[7]='T';    str[8]='U';    str[9]='V';    str[10]='W';    str[11]='w';    str[12]='X';    str[13]='x';    str[14]='Y';    int ll=0;    for(int i=0,j=l-1; i<l/2; i++,j--)    {        if(s[i]==s[j])        {            for(int k=0; k<15; k++)                if(s[i]==str[k])                {                    ll+=2;                    break;                }        }        else if((s[i]=='b'&&s[j]=='d')||(s[j]=='b'&&s[i]=='d')||(s[i]=='p'&&s[j]=='q')||(s[j]=='p'&&s[i]=='q'))            ll+=2;        else            break;    }    if(l%2==0&&ll==l)        printf("TAK\n");    else    {        for(int i=0; i<15; i++)            if(s[l/2]==str[i])            {                ll+=1;                break;            }        if(ll==l)            printf("TAK\n");        else            printf("NIE\n");    }    return 0;}
0 0
原创粉丝点击