CodeForces #362 div2 B. Barnicle

题目链接: B. Barnicle

题意:给出科学计数法 转化成十进制的整数或小数 并输出。

思路:暑假训练赛见过了,当时大腿A掉了,并表示是道水题。

   刷CF再次遇见,毫不留情WA了几次。比如:

0.e0       0

1.0e0     1

   突然觉得自己不能再依赖CF这种看着sample dbug的模式了。

附代码:

/// 给出科学计数法 转化成十进制的整数或小数 并输出

#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;

string str;

int main() {
    //freopen("in.cpp", "r", stdin);
    while(cin >> str) {
        string ans = "";
        int len = str.length();
        int lose;
        for (int i=len-1; i>=0; --i) {
            if (str[i] == ‘e‘) {
                lose = i;
                break;
            }
        }

        int a = str[0] - ‘0‘;
        if (a == 0) {
            int endd = 0;
            for (int i=lose-1; i>=0; --i){
                if (str[i] > ‘0‘ && str[i] <= ‘9‘) {
                    endd = i;
                    break;
                }
            }
            str.resize(endd+1);
            cout << str << endl;
            continue;
        }

        ans += str[0];
        int b = 0;
        for (int i=lose+1; i<len; ++i) {
            b = b*10 + str[i]-‘0‘;
        }
        int cnt1 = 0;
        bool first = false; //
        for (int i=2; i<lose; ++i) {
            if (cnt1 < b) {
                ans += str[i];
            }
            else {
                if (first == false) {
                    first = true;
                    ans += ‘.‘;
                }
                ans += str[i];
            }
            cnt1++;
        }
        while(cnt1 < b) {
            ans += ‘0‘;
            cnt1++;
        }
        if (ans[1] == ‘.‘) {
            int anslen = ans.length();
            bool ok = false;
            for (int i=2; i<anslen; ++i) {
                if (ans[i] > ‘0‘ && ans[i] <= ‘9‘) {
                    ok = true;
                    break;
                }
            }
            if (!ok) ans.resize(1);
        }
        cout << ans << endl;
    }
    return 0;
}
时间: 2024-08-28 01:06:40

CodeForces #362 div2 B. Barnicle的相关文章

Codeforces 583 DIV2 Robot&#39;s Task 贪心

原题链接:http://codeforces.com/problemset/problem/583/B 题意: 就..要打开一个电脑,必须至少先打开其他若干电脑,每次转向有个花费,让你设计一个序列,使得总花费最小. 题解: 就傻傻的走就好..从左走到右,再走回来,更新序列和答案就好. 代码: #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #define MA

Codeforces #180 div2 C Parity Game

// Codeforces #180 div2 C Parity Game // // 这道题的题目意思就不解释了 // // 题目有那么一点难(对于我而言),不多说啦 // // 解题思路: // // 首先如果a串和b串相等,不多说直接YES // 如果b串全是0,直接YES // 注意到a串有一个性质,1的个数不会超过本身的加1. // a有个1的上限设为x,b有个1的个数设为y,则如果x < y // 那么直接NO. // // 现在一般情况下,就是模拟啦,找到a的后缀和b的前缀一样的

Codeforces #246(div2)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <ti

Codeforces #245(div2)

A:A. Points and Segments (easy) 题目看了n久,开始觉得尼玛这是div2的题目么,题目还标明了easy.. 意思是给你一n个点,m个区间,在n个点上放蓝球或者红球,然后让你找一种选择方案使得m个区间内的蓝球和红球数量之差不超过1. 开始想过用dfs,不过这只是div2的A题而已.. 然后想了下,直接输出010101序列不就可以么. 交了一发,发现要先排个序,再输出就可以了. AC代码: #include<iostream> #include<cstdio&g

codeforces#327 div2

codeforces#327 div2 这场状态不好有点可惜,题目都不难,而且很好.. A题:水题. #include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; typedef lo

codeforces#FF(div2) DZY Loves Sequences

n个数,可以任意改变其中一个数,求最长的上升子区间长度 思路:记录一个from[i]表示从位置i的数开始最长的上升区间长度 记录一个to[i]表示到位置i的数所能达到的最长上升区间长度 枚举要改变的数的位置i,此时能达到的长度为to[i - 1] + from[i + 1] + 1,取最大值 //#pragma comment(linker, "/STACK:102400000,102400000") //HEAD #include <cstdio> #include &l

Codeforces 258 Div2

A题,n*m根木棍,相交放置,轮流取走相交的两根,最后谁不能行动,则输掉. min(n,m)&1 为1则先取者赢. B题,给定一个长度为n,且各不相同的数组,问能否通过交换连续一段L....R使得变成单调递增. 如果一开始就是递增的,那么直接输出L...R就是1 1,交换一个就行了:否则判断中间是否有且一段单调递减,且两端交换后使得数组递增. 代码: 1 //Template updates date: 20140718 2 #include <iostream> 3 #include

Codeforces #263 div2 解题报告

比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注册的时候很想好好的做一下,但是网上喝了个小酒之后,也就迷迷糊糊地看了题目,做了几题,一觉醒来发现rating掉了很多,那个心痛啊! 不过,后来认真的读了题目,发现这次的div2并不是很难! 官方题解:http://codeforces.com/blog/entry/13568 A. Appleman and Easy Task 解析: 一个水题,判断每个细胞周围是否都是有偶数个相邻细胞.   代码

codeforces#333 div2 B. Approximating a Constant Range

http://codeforces.com/contest/602/problem/B 这道题的两种做法, 滑窗+线段树查询区间最值: #include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) using namespace std; typedef long long ll; const int maxn=1000100; const int