1093 字符串A+B (20 分)
//1093 字符串A+B (20 分)
#include
using namespace std;
int main(){
ios::sync_with_stdio(0);
string s1, s2, s;
int hash[200] = {0};
getline(cin, s1);
getline(cin, s2);
s = s1 + s2;
//哈希去重
for (int i = 0; i < s.size();i++){
if(hash[s[i]]==0)
cout << s[i];
hash[s[i]] = 1;
}
return 0;
}
1095 解码PAT准考证 (25 分)
#include
using namespace std;
//1095 解码PAT准考证 (25 分)
struct node{
string t;
int value;
};
bool cmp(const node &a,const node &b){
return a.value != b.value ? a.value > b.value : a.t < b.t;
}
int main(){
ios::sync_with_stdio(0);
int n, k, num;
string s;
cin >> n >> k;
vector v(n);
for (int i = 0; i < n;i++)
cin >> v[i].t >> v[i].value;
for (int i = 1; i <= k; i++)
{
cin >> num >> s;
printf("Case %d: %d %sn", i, num, s.c_str());
vector ans;
int cnt = 0;
int sum = 0;
if (num == 1)
{
for (int j = 0; j < n; j++)
{
if (v[j].t[0] == s[0])
ans.push_back(v[j]);
}
}
else if (num == 2)
{
for (int j = 0; j < n; j++)
{
if (v[j].t.substr(1, 3) == s)
{
cnt++;
sum += v[j].value;
}
}
if (cnt != 0)
printf("%d %dn", cnt, sum);
}
else if (num == 3)
{
unordered_map m;
for (int j = 0; j < n; j++)
{
if (v[j].t.substr(4, 6) == s)
m[v[j].t.substr(1, 3)]++;
}
for (auto it : m)
ans.push_back({it.first, it.second});
}
sort(ans.begin(), ans.end(), cmp);
for (int j = 0; j < ans.size(); j++)
printf("%s %dn", ans[j].t.c_str(), ans[j].value);
if (((num == 1 || num == 3) && ans.size() == 0) || (num == 2 && cnt == 0))
printf("NAn");
}
return 0;
}
1086 就不告诉你 (15 分)
#include
using namespace std;
//1086 就不告诉你 (15 分)
int main(){
ios::sync_with_stdio(0);
int a, b;
cin>>a>>b;
int c = a * b;
int arr[100]={0};
int i = 0;
while(c){
arr[i++] = c % 10;
c /= 10;
}
int flag=1;
for (int j = 0; j
#include
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
string t=to_string(a*b);
reverse(t.begin(),t.end());//反转
b=0;
a=t.length();
while(t[b]=='0'&&b
1081 检查密码 (15 分)
#include
using namespace std;
//1081 检查密码 (15 分)
int main(){
int t;
cin>>t;getchar();//读回车
while(t--){
string s;
getline(cin,s);
if(s.length()>=6){
int a=0,b=0,c=0;
for(int j=0;j
1029 旧键盘 (20 分)
#include
using namespace std;
//1029 旧键盘 (20 分)
int main(){
ios::sync_with_stdio(0);
string s1, s2;
cin >> s1;
cin >> s2;
int hash[100] = {0};
for (int i = 0; i < s1.length(); i++) {
s1[i] = toupper(s1[i]);//小写转大写;
}
for (int i = 0; i < s2.length(); i++) {
s2[i] = toupper(s2[i]);
}
for (int i = 0; i < s1.length(); i++) {
int j;
for (j = 0; j < s2.length(); j++) {
if (s1[i] == s2[j]) {
break;
}
}
if (j == s2.length() && hash[s1[i]]==0) {
cout << s1[i];
hash[s1[i]] = 1;
}
}
return 0;
}