sdut-集合相等问题 (Python)

思路:只要每一次读入第二个数组的数时,判断一下第一个数组中是否存在即可。具体蒙特卡洛方法请自行百度 ,本题并未真实体现算法思想。

#sdut-集合相等问题

n = input()
n = int(n)

arr1 = list(input())

arr2 = list(input())
    
flag = True;

for item1 in arr1:
    f = 0;
    for item2 in arr2:
        if item1 == item2:
            f = 1;
    if f == 0:
        flag = False
        break
        
if flag:
    print("YES")
else:
    print("NO")

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个简单的学生集合的示例代码,您可以参考: ```c++ #include <iostream> #include <string> #include <vector> using namespace std; class Student { private: string name; int age; double score; public: Student(string n, int a, double s) : name(n), age(a), score(s) {} string getName() const { return name; } int getAge() const { return age; } double getScore() const { return score; } }; class StudentCollection { private: vector<Student> students; public: void addStudent(Student s) { students.push_back(s); } void removeStudent(Student s) { for (vector<Student>::iterator it = students.begin(); it != students.end(); ++it) { if (it->getName() == s.getName()) { students.erase(it); break; } } } void printStudents() const { for (vector<Student>::const_iterator it = students.begin(); it != students.end(); ++it) { cout << "Name: " << it->getName() << ", Age: " << it->getAge() << ", Score: " << it->getScore() << endl; } } }; int main() { StudentCollection sc; sc.addStudent(Student("Tom", 18, 90)); sc.addStudent(Student("Jerry", 20, 80)); sc.addStudent(Student("Alice", 19, 85)); sc.printStudents(); sc.removeStudent(Student("Jerry", 20, 80)); sc.printStudents(); return 0; } ``` 这个示例代码中,定义了一个 `Student` 类和一个 `StudentCollection` 类。其中 `Student` 类表示一个学生,包括学生姓名、年龄、分数等信息。`StudentCollection` 类表示一个学生集合,包括添加学生、删除学生、打印学生信息等操作。在 `main` 函数中,演示了如何使用 `StudentCollection` 类来管理学生集合

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值