• poj 2121 && poj 2403


    题目:http://poj.org/problem?id=2121

    很很简单的题,权当用map 做着玩吧,就是给出英文的数,然后让你转换成数字,注意当是 百,千,百万的时候的处理,不为别的,就为了那个打表,打的眼晕,最后还是打错了,交了两次才发现,汗

    View Code
     1 #include<iostream>
     2 #include<sstream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<string>
     7 #include<vector>
     8 #include<map>
     9 #include<queue>
    10 #include<stack>
    11 #include<cmath>
    12 #include<set>
    13 #define N 5010
    14 #define inf 100000000
    15 #define _clr(a,val) (a,val,sizeof(a))
    16 #define Min(x, y)   x < y ? x : y
    17 #define Max(x, y)   x < y ? y : x
    18 
    19 using namespace std;
    20 
    21 typedef long long ll;
    22 
    23 char str[N];
    24 map<string,int>ma;
    25 void init()
    26 {
    27     ma["zero"] = 0, ma["one"] = 1, ma["two"] = 2;
    28     ma["three"] = 3, ma["four"] = 4, ma["five"] = 5;
    29     ma["six"] = 6, ma["seven"] = 7, ma["eight"] = 8;
    30     ma["nine"] = 9, ma["ten"] = 10, ma["eleven"] = 11;
    31     ma["twelve"] = 12, ma["thirteen"] = 13, ma["fourteen"] = 14;
    32     ma["fifteen"] = 15, ma["sixteen"] = 16, ma["seventeen"] = 17;
    33     ma["eighteen"] = 18, ma["nineteen"] = 19, ma["twenty"] = 20;
    34     ma["thirty"] = 30, ma["forty"] = 40, ma["fifty"] = 50;
    35     ma["sixty"] = 60, ma["seventy"] = 70, ma["eighty"] = 80;
    36     ma["ninety"] = 90;
    37     ma["hundred"] = 100, ma["thousand"] = 1000, ma["million"] = 1000000;
    38 }
    39 int main()
    40 {
    41     //freopen("data.txt","r",stdin);
    42     init();
    43     while(gets(str))
    44     {
    45         ll sum = 0;
    46         ll tsum = 0;
    47         if(!strcmp(str,"")) break;
    48         istringstream s(str);
    49         while(s >> str)
    50         {
    51             //cout<<"str = "<<str<<endl;
    52             if(!strcmp(str,"negative")) printf("-");
    53             if(strcmp(str,"million") && strcmp(str,"thousand") && strcmp(str,"hundred") && strcmp(str,"zero")) sum += ma[str];
    54             else if(!strcmp(str,"hundred") || !strcmp(str,"zero")) sum *= ma[str];
    55             else if(!strcmp(str,"thousand"))
    56             {
    57                 tsum += sum * 1000, sum = 0;
    58             }
    59             else if(!strcmp(str,"million"))
    60             {
    61                 tsum += sum * 1000000, sum = 0;
    62             }
    63         }
    64         //printf("%I64d\n",tsum + sum);
    65         cout<<(tsum + sum)<<endl;
    66     }
    67     return 0;
    68 }

    题目:http://poj.org/problem?id=2403

    比上个还简单的题,先是给出 N 个单词,每个单词对应一个权值,下面给出M串很长的字符串,让你统计在每个字符串里出现的单词的权值总和

    View Code
     1 #include<iostream>
     2 #include<sstream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<string>
     7 #include<vector>
     8 #include<map>
     9 #include<queue>
    10 #include<stack>
    11 #include<cmath>
    12 #include<set>
    13 #define N 5010
    14 #define inf 100000000
    15 #define _clr(a,val) (a,val,sizeof(a))
    16 #define Min(x, y)   x < y ? x : y
    17 #define Max(x, y)   x < y ? y : x
    18 
    19 using namespace std;
    20 
    21 typedef long long ll;
    22 
    23 char str[N];
    24 
    25 map<string,int>ma;
    26 
    27 int main()
    28 {
    29     //freopen("data.txt","r",stdin);
    30     int n,m;
    31     int x;
    32     while(scanf("%d%d",&n,&m) != EOF)
    33     {
    34         for(int i = 0; i < n; i++)
    35         {
    36             cin>>str>>x;
    37             ma[str] = x;
    38         }
    39         while(m--)
    40         {
    41             ll sum = 0;
    42             while(gets(str))
    43             {
    44                 if(!strcmp(str,".")) break;
    45                 istringstream s(str);
    46                 while(s >> str)
    47                 {
    48                     sum += ma[str];
    49                 }
    50             }
    51             cout<<sum<<endl;
    52         }
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    为什么重复值高的字段不能建索引(比如性别字段等)
    【转】微服务架构技术栈选型手册
    【转】使用索引为什么能提高查询速度?
    SpringBoot读取配置文件(从classpath/file读取yml/properties文件)
    集合总结--ArrayList、LinkedList、HashMap
    HashMap问答
    【转】http的keep-alive和tcp的keepalive区别
    【转】大数据分析中Redis怎么做到220万ops
    哪个中年IT男不是一边面对危机,一边咬牙硬抗【转】
    SVN clean失败解决方法【转】
  • 原文地址:https://www.cnblogs.com/fxh19911107/p/2645225.html
Copyright © 2020-2023  润新知