zoukankan      html  css  js  c++  java
  • ZOJ2971 Give Me the Number 【模拟】

    这道题目使用Map。 然后一次性遍历下来即可。 QAQ

    注意初始化的时候小心点不要错..

    Source Code:

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <string>
    #include <map>
    #include <set>
    #include <list>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #define Max(a,b) (((a) > (b)) ? (a) : (b))
    #define Min(a,b) (((a) < (b)) ? (a) : (b))
    #define Abs(x) (((x) > 0) ? (x) : (-(x)))
    #define MOD 1000000007
    #define pi acos(-1.0)
    
    using namespace std;
    
    typedef long long           ll      ;
    typedef unsigned long long  ull     ;
    typedef unsigned int        uint    ;
    typedef unsigned char       uchar   ;
    
    template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
    template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;}
    
    const double eps = 1e-7      ;
    const int N = 210            ;
    const int M = 1100011*2      ;
    const ll P = 10000000097ll   ;
    const int MAXN = 100000      ;
    const int INF = 0x3f3f3f3f   ;
    const int MAX = 10500        ;
    
    map <string, int> g;
    
    void init(){
        g["zero"] = 0, g["one"] = 1, g["two"] = 2, g["three"] = 3, g["four"] = 4;
        g["five"] = 5, g["six"] = 6, g["seven"] = 7, g["eight"] = 8, g["nine"] = 9;
        g["ten"] = 10, g["eleven"] = 11, g["twelve"] = 12, g["thirteen"] = 13, g["fourteen"] = 14;
        g["fifteen"] = 15, g["sixteen"] = 16, g["seventeen"] = 17, g["eighteen"] = 18, g["nineteen"] = 19;
        g["twenty"] = 20, g["thirty"] = 30, g["forty"] = 40, g["fifty"] = 50, g["sixty"] = 60;
        g["seventy"] = 70, g["eighty"] = 80, g["ninety"] = 90;
    }
    
    int main(){
        std::ios::sync_with_stdio(false);
        int i, j, t, k, u, v, x, y, numCase = 0;
        init();
        cin >> t;
        cin.get();//
        while(t--){
            string ss;
            getline(cin, ss, '
    ');//
            ss += ' ';
            int len = ss.length();
            int num = 0, cur = 0, ans = 0;
            for(i = 0; i < len; ++i){
                if(ss[i] == ' '){
                    string str = ss.substr(num, i - num);
                    num = i + 1;
                    if(str == "and"){
                        continue;
                    } else if(str == "million"){
                        cur *= 1000000;
                        ans += cur;
                        cur = 0;
                    } else if(str == "thousand"){
                        cur *= 1000;
                        ans += cur;
                        cur = 0;
                    } else if(str == "hundred"){
                        cur *= 100;
                    } else{
                        cur += g[str];
                    }
                }
            }
            ans += cur;
            cout << ans << endl;
        }
    
        return 0;
    }
  • 相关阅读:
    通过电脑chrome调试手机真机打开的微信H5页面,调试电脑微信H5页面
    关于神策埋点数据采集
    jmeter控制仅一次登录的三种方案
    win10下mysql8.0.19解压版的安装教程
    mysql中的case when then 的用法
    python+openpyxl的excel的相关读写
    使用Gitlab-CI 实现NetCore项目Docker化并部署到阿里云K8S
    NetCore 中间件获取请求报文和返回报文
    WebApi 通过拦截器设置特定的返回格式
    NetCore AutoMapper的封装
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/3608716.html
Copyright © 2011-2022 走看看