前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >pta帅到没朋友(c/c++版)

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

作者头像
用户11036582
发布2024-03-21 18:34:27
790
发布2024-03-21 18:34:27
举报

给大家分享一句我很喜欢我话: 知不足而奋进,望远山而前行!!! 铁铁们,成功的路上必然是孤独且艰难的,但是我们不可以放弃,远山就在前方,但我们能力仍然不足,所有我们更要奋进前行!!! 今天我们更新了帅到没朋友内容,

题目介绍

C语言版本

代码语言:javascript
复制
#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++版本

代码语言:javascript
复制
#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";    
	}
} 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-03-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目介绍
  • C语言版本
  • C++版本
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档