A. Anton and Polyhedrons

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
inputCopy
4
Icosahedron
Cube
Tetrahedron
Dodecahedron
outputCopy
42
inputCopy
3
Dodecahedron
Octahedron
Octahedron
outputCopy
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.

较简洁的方法

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    int n;
    while(cin >> n)
    {
        int cnt = 0;
        for(int i = 0; i < n; ++i)
        {
            char s[20];
            cin >> s;
            switch(s[0])
            {
            case 'T':
                cnt += 4;
                break;
            case 'C':
                cnt += 6;
                break;
            case 'O':
                cnt += 8;
                break;
            case 'D':
                cnt += 12;
                break;
            case 'I':
                cnt += 20;
                break;
            default:
                break;
            }
            memset(s, 0, sizeof(s));
        }
        cout << cnt << '\n';
    }
    return 0;
}

用map

#include <map>
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    int n;
    while(cin >> n)
    {
        int cnt = 0;
        map<string, int> mp;
        mp.insert(pair<string, int> ("Tetrahedron", 4) );
        mp.insert(pair<string, int> ("Cube", 6) );
        mp.insert(pair<string, int> ("Octahedron", 8) );
        mp.insert(pair<string, int> ("Dodecahedron", 12) );
        mp.insert(pair<string, int> ("Icosahedron", 20) );
        for(int i = 0; i < n; ++i)
        {
            string s;
            cin >> s;
            switch(mp[s])
            {
            case 4:
                cnt += 4;
                break;
            case 6:
                cnt += 6;
                break;
            case 8:
                cnt += 8;
                break;
            case 12:
                cnt += 12;
                break;
            case 20:
                cnt += 20;
            }
        }
        cout << cnt << '\n';
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值