zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    day01--计算机硬件基础笔记
    22 Jun 18 Django,ORM
    21 Jun 18 Django,ORM
    20 Jun 18 复习, mysql
    20 Jun 18 Django,ORM
    19 Jun 18 复习, 正则表达式
    19 Jun 18 Django
    15 Jun 18 复习, shutil模块
    15 Jun 18 Django
    14 Jun 18 复习, form表单
  • 原文地址:https://www.cnblogs.com/fxh19911107/p/2645225.html
Copyright © 2011-2022 走看看