NOJ [1118] Marisa's Affair

本文介绍了一种通过编程方式统计TouHou中角色Kirisame Marisa与其他女巫绯闻数量的方法。该方法使用C++实现,通过读取一系列输入数据来记录Marisa与不同角色之间的绯闻次数及好感度,并最终按好感度和绯闻次数排序输出结果。

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

  • 问题描述
  • Everyone knows that Kirisame Marisa(きりさめ·まりさ) often has affaires with other witches in TouHou.
    For example, she has an affair with Reimu today and tomorrow is Flandre.
    You have to make clear that how many witches she has affairs with.

  • 输入
  • This problem has several cases.
    The first line of each case contains an integer N(0 < N <= 5000).
    Then follows N lines. The ith has a name NAMEi and an integer Hi(0 < Hi < 20000), means at the ith day Marisa has an affair with NAMEi, and NAMEi increases Hi likability.
    You can consider that every name only contains uppercase and lowercase letters, and not longer then 20;
  • 输出
  • For each case, you should output like that:
    At the first line, you should output how many witches Marisa has affaires with;
    Then each line output like that:
    The name of the witch, the likability with that witch and the time(s) they have affaires. Order by likability descending.
    If their likabilities are the same, then order by affair times descending.
    If their likabilities and affair times are the same, then order by lexicographical order increasing.

    看懂题之后,其实这是一道水题


    上代码
    #include<stdio.h>
    #include<iostream>
    #include<map>
    #include<string.h>
    #include<algorithm>
    
    using namespace std;
    
    struct affair
    {
    	char name[25];
    	long long  likability,times;
    }witches[5010];
    
    char temp[22];
    
    int cmp(affair a,affair b)
    {
    	if(a.likability != b.likability)
    		return a.likability > b.likability;
    	else
    	{
    		if(a.times != b.times)
    			return a.times > b.times;
    		else
    			return strcmp(a.name,b.name)<0;
    	}
    }
    
    int main()
    {
    	int n,i;
    	while(~scanf("%d",&n))
    	{
    		long long d, k=1;
    		map<string,int>affairs;
    		//affairs.clear();
    		for(i=0;i<=n;i++)
    		{
    			witches[i].likability=0;
    			witches[i].times=0;
    		}
    		for(i=0;i<n;i++)
    		{
    			scanf("%s %lld",temp,&d);
    			if(affairs[temp]==NULL)
    			{
    				affairs[temp]=k;
    				strcpy(witches[k].name,temp);
    				witches[k].times=1;
    				witches[k].likability+=d;
    				k++;
    			}
    			else
    			{
    				witches[affairs[temp]].likability+=d;
    				witches[affairs[temp]].times++;
    			}
    		}
    		sort(witches+1,witches+k,cmp);
    		printf("%d\n",k-1 );
    		for(i=1;i<k;i++)
    			printf("%s %lld %lld\n",witches[i].name,witches[i].likability,witches[i].times);
    	}
    	return 0;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值