zoukankan      html  css  js  c++  java
  • 下厨房

    题目描述
    牛牛想尝试一些新的料理,每个料理需要一些不同的材料,问完成所有的料理需要准备
    多少种不同的材料。 输入描述: 每个输入包含 1 个测试用例。每个测试用例的第 i 行,表示完成第 i 件料理需要哪
    些材料,各个材料用空格隔开,输入只包含大写英文字母和空格,输入文件不超过 50
    行,每一行不超过 50 个字符。 输出描述: 输出一行一个数字表示完成所有料理需要多少种不同的材料。

    采用容器set C++

    #include <iostream>
    #include <set>
    #include <string>
    
    using namespace std;
    int main()
    {
        string s;
        set<string> str;
        while (cin>>s)
        {
            str.insert(s);
        }
        cout << str.size() << endl;
    }

    采用容器map C++

    #include <iostream>
    #include <map>
    #include <string>
    
    using namespace std;
    int main()
    {
        string s;
        map<string,int> str;
        while (cin>>s)
        {
            str[s]=1;
        }
        cout << str.size() << endl;
    }

    采用多维字符数组,比较字符串 C++

    #include <iostream>
    #include <string.h>
    
    using namespace std;
    
    int main() {
        //定义多维数组存储所有的字符串
        char s[1000][100] = { 0 };
        //定义临时变量存储输入的字符串
        char str[100];
        int j = 0;
        int count = 0;
        while (cin >> str) {
            if (j == 0) {
                strcpy(s[j], str);
                j++;count++;
            }
            bool flag = false;
            for (int i = 0;i < j;i++) {
                if (strcmp(s[i], str) == 0) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                strcpy(s[j], str);
                j++;count++;
            }
    
        }
        cout << count << endl;
    }

    python

    import sys
    std_in = sys.stdin
    tmp = set()
    for line in std_in:
        for food in line.split():
            tmp.add(food)
    print(len(tmp))
  • 相关阅读:
    Spring的bean管理(注解)
    IOC 和DI的区别
    java spring属性注入
    Java 接口
    JAVA 修饰符
    Day19-File操作-创建 删除,文件过滤
    Eclipse快捷键大全
    Day17总结
    启动人人项目遇到的问题
    Eclipse 各版本号
  • 原文地址:https://www.cnblogs.com/lyf-sunicey/p/8430242.html
Copyright © 2011-2022 走看看