pta帅到没朋友(c/c++版)

9efbcbc3d25747719da38c01b3fa9b4f.gif

 c语言中的小小白-CSDN博客c语言中的小小白关注算法,c++,c语言,贪心算法,链表,mysql,动态规划,后端,线性回归,数据结构,排序算法领域.https://blog.csdn.net/bhbcdxb123?spm=1001.2014.3001.5343

给大家分享一句我很喜欢我话:

知不足而奋进,望远山而前行!!!

铁铁们,成功的路上必然是孤独且艰难的,但是我们不可以放弃,远山就在前方,但我们能力仍然不足,所有我们更要奋进前行!!!

今天我们更新了帅到没朋友内容,

🎉 欢迎大家关注🔍点赞👍收藏⭐️留言📝

题目介绍

C语言版本

#include <stdio.h>
#include <stdbool.h>
#define MAX_N 10000

int main() {
    int n = 0;
    scanf("%d", &n);
    
    int no_handsome[MAX_N];
    int no_handsome_size = 0;
    
    for (int i = 0; i < n; i++) {
        int k = 0;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int temp = 0;
            scanf("%d", &temp);
            if (k > 1) {
                no_handsome[no_handsome_size++] = temp;
            }
        }
    }

    int m = 0;
    scanf("%d", &m);
    
    int handsome[MAX_N];
    int handsome_size = 0;
    bool flag = true;
    
    for (int i = 0; i < m; i++) {
        int temp;
        scanf("%d", &temp);
        if (no_handsome_size > 0) {
            bool found = false;
            for (int j = 0; j < no_handsome_size; j++) {
                if (temp == no_handsome[j]) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                bool new_handsome = true;
                for (int j = 0; j < handsome_size; j++) {
                    if (temp == handsome[j]) {
                        new_handsome = false;
                        break;
                    }
                }
                if (new_handsome) {
                    if (!flag) {
                        printf(" ");
                    }
                    printf("%05d", temp);
                    flag = false;
                    handsome[handsome_size++] = temp;
                }
            }
        }
    }

    if (handsome_size == 0) {
        printf("No one is handsome");
    }
    
    return 0;
}

C++版本

#include<iostream>
#include<set>

using namespace std;
int main()
{    
	int n=0;    
	cin>>n;    
	set<int> no_handsome;    
	for(int i=0;i<n;i++)    
	{        
		int k=0;        
		cin>>k;        
		for(int j=0;j<k;j++)        
		{            
			int temp=0;            
			cin>>temp;            
			if(k>1)            
			{                
				no_handsome.insert(temp);            
			}           
		}    
	}    
	int m=0;    
	cin>>m;     
	set<int> handsome;    
	bool flag=true;    
	for(int i=0;i<m;i++)    
	{        
		int temp;        
		cin>>temp;        
		if(no_handsome.find(temp)==no_handsome.end())        
		{            
			if(handsome.find(temp)==handsome.end())            
			{                
				if(!flag)                
				{                    
					cout<<" ";                
				}                
				printf("%05d",temp);                
				flag=false;            
			}            
			handsome.insert(temp);        
		}    
	}    
	if(handsome.size()==0)    
	{        
		cout<<"No one is handsome";    
	}
} 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值