PAT A1116的素数STL模拟,‘Come on! Let's C’怎么改成长尾?

2026-04-16 20:561阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计272个文字,预计阅读时间需要2分钟。

PAT A1116的素数STL模拟,‘Come on! Let's C’怎么改成长尾?

题目描述:对一组字符串进行去重处理,并输出去重后的字符串列表。

链接:无

素材判断:是

PAT A1116的素数STL模拟,‘Come on! Let's C’怎么改成长尾?

map存储:是

代码:pythondef remove_duplicates(strings): seen=set() unique_strings=[] for string in strings: if string not in seen: unique_strings.append(string) seen.add(string) return unique_strings

示例strings=[apple, banana, apple, cherry, banana]print(remove_duplicates(strings))

题目描述

链接
素数判断+map存储

代码

#include<bits/stdc++.h> using namespace std; int n,k; map<string, string> mp; map<string, bool> check; bool is_prime(int n){ if(n < 2) return false; for(int i=2; i<=sqrt(n); i++){ if(n % i == 0) return false; } return true; } int main(){ cin>>n; string s; for(int i=1;i<=n;i++){ cin>>s; if(i==1) mp[s] = "Mystery Award"; else if(is_prime(i)){ mp[s] = "Minion"; }else{ mp[s] = "Chocolate"; } } cin>>k; while(k--){ cin>>s; if(mp.find(s) == mp.end()){ cout<<s<<": Are you kidding?"<<endl; }else if(check[s] == false){ check[s] = true; cout<<s<<": "<<mp[s]<<endl; }else{ cout<<s<<": Checked"<<endl; } } }

本文共计272个文字,预计阅读时间需要2分钟。

PAT A1116的素数STL模拟,‘Come on! Let's C’怎么改成长尾?

题目描述:对一组字符串进行去重处理,并输出去重后的字符串列表。

链接:无

素材判断:是

PAT A1116的素数STL模拟,‘Come on! Let's C’怎么改成长尾?

map存储:是

代码:pythondef remove_duplicates(strings): seen=set() unique_strings=[] for string in strings: if string not in seen: unique_strings.append(string) seen.add(string) return unique_strings

示例strings=[apple, banana, apple, cherry, banana]print(remove_duplicates(strings))

题目描述

链接
素数判断+map存储

代码

#include<bits/stdc++.h> using namespace std; int n,k; map<string, string> mp; map<string, bool> check; bool is_prime(int n){ if(n < 2) return false; for(int i=2; i<=sqrt(n); i++){ if(n % i == 0) return false; } return true; } int main(){ cin>>n; string s; for(int i=1;i<=n;i++){ cin>>s; if(i==1) mp[s] = "Mystery Award"; else if(is_prime(i)){ mp[s] = "Minion"; }else{ mp[s] = "Chocolate"; } } cin>>k; while(k--){ cin>>s; if(mp.find(s) == mp.end()){ cout<<s<<": Are you kidding?"<<endl; }else if(check[s] == false){ check[s] = true; cout<<s<<": "<<mp[s]<<endl; }else{ cout<<s<<": Checked"<<endl; } } }