PAT-练习集-L1-035. 情人节

本文介绍了一个C++程序示例,通过使用标准库中的map来记录输入的不同字符串出现次数,并输出特定位置的字符串。该程序展示了如何利用map进行高效的数据处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//传送门:https://www.patest.cn/contests/gplt/L1-035
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
using namespace std;
/*题意:
  用 map<string,int> 记录这个人名是否出现过,
  用 cot 记录出现不同人名的个数,
  用 string ans1,ans2 分别记录第2、14个出现的人名。
*/
#define N 1005
map<string,int>mp;

int main()
{
   string s;
   string ans1,ans2;
   int cot = 0;
   while(cin>>s){
      if(s==".") break;
      if(mp[s]) continue;  //已经出现跳过
      cot++;               
      if(cot==2) ans1 = s; 
      if(cot==14) ans2 = s;
      mp[s]++;
   }
   if(cot<2) cout<<"Momo... No one is for you ...";
   else if(cot<14) cout<<ans1<<" is the only one for you...";
   else cout<<ans1<<" and "<<ans2<<" are inviting you to dinner...";
   return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值