Anton and Polyhedrons

举报
辰chen 发表于 2022/06/14 23:59:25 2022/06/14
【摘要】 文章目录 一、 Anton and Polyhedrons总结 一、 Anton and Polyhedrons 本题链接:Anton and Polyhedrons 题目: A. ...


一、 Anton and Polyhedrons

本题链接Anton and Polyhedrons

题目
A. Anton and Polyhedrons
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Anton’s favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:

Tetrahedron. Tetrahedron has 4 triangular faces.
Cube. Cube has 6 square faces.
Octahedron. Octahedron has 8 triangular faces.
Dodecahedron. Dodecahedron has 12 pentagonal faces.
Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
在这里插入图片描述
Anton has a collection of n polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000)— the number of polyhedrons in Anton’s collection.

Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton’s collection. The string can look like this:

“Tetrahedron” (without quotes), if the i-th polyhedron in Anton’s collection is a tetrahedron.
“Cube” (without quotes), if the i-th polyhedron in Anton’s collection is a cube.
“Octahedron” (without quotes), if the i-th polyhedron in Anton’s collection is an octahedron.
“Dodecahedron” (without quotes), if the i-th polyhedron in Anton’s collection is a dodecahedron.
“Icosahedron” (without quotes), if the i-th polyhedron in Anton’s collection is an icosahedron.
Output
Output one number — the total number of faces in all the polyhedrons in Anton’s collection.

Examples
input
4
Icosahedron
Cube
Tetrahedron
Dodecahedron
output
42

input
3
Dodecahedron
Octahedron
Octahedron
output
28

Note
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.

本博客给出本题截图
在这里插入图片描述
在这里插入图片描述

题意:不同的字符串代表不同的数字,输入n个字符串,问这些字符串对应数字的和

AC代码

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    map<string, int> m;
    m["Tetrahedron"] = 4;
    m["Cube"] = 6;
    m["Octahedron"] = 8;
    m["Dodecahedron"] = 12;
    m["Icosahedron"] = 20;
    
    int n;
    cin >> n;
    
    int res = 0;
    while (n -- )
    {
        string a;
        cin >> a;
        res += m[a];
    }
    
    cout << res << endl;
    
    return 0;
}

总结

水题,不解释

文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。

原文链接:chen-ac.blog.csdn.net/article/details/117717725

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。