L1-020 帅到没朋友

本文介绍了两个C++程序,一个是解决一个关于找出朋友圈中唯一不重复出现的人的错误代码,另一个是神仙代码,用于统计朋友圈中特定用户被添加的次数。
摘要由CSDN通过智能技术生成

一、链接

L1-020 帅到没朋友

二、题目

三、错误代码

 写了一个晚自习就拿了两分。然后在csdn上找到一个特别棒的思路。

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n=0,j=0,read=0,beau=0,sum=0,all=1,rep=0,time=0;
	int num=0;
	int str[100000];
	int read_str[10000];
	int repeat[10000];
	cin>>n;
	for(;n--;)
	{
		cin>>num;
		if(num!=1)
		{
			sum+=num;
			for(;j<sum;j++)
			{
				cin>>str[j];
			}
		}
		
	}
	cin>>read;
	for(int k=0;k<read;k++)
	{
		cin>>read_str[k];
	}
	for(int l=0;l<read;l++)
	{
		beau=1;
		for(int flag=0;flag<j-1;flag++)
		{
			if(read_str[l]==str[flag])
			{
				beau=0;
				break;
			}
		}
		if(beau!=0)
		{
			time++;
			rep=0;
			for(int x=0;x<time;x++)
			{
				if(read_str[l]==repeat[x])
				{
					rep=1;
				}
			}
			all=0;
			repeat[time-1]=read_str[l];
			if(rep!=1)
			cout<<read_str[l]<<" ";
		}
	}
	if(all!=0)
		cout<<"No one is handsome"<<endl;
	else
	cout<<'\b';
	return 0;
}

四、神仙代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,a[100001]={0},t,b[10001],k=0;
	cin>>n;
	for(;n--;)
	{
		cin>>m;
		for(int l=0;l<m;l++)
			{
				cin>>t;
				if(m!=1)//防止自恋狂多次加朋友圈 
				a[t]++;
			}
	}
	cin>>n;
	for(;n--;)
		{
			cin>>t;
			if(a[t]==0)
			{
				b[k++]=t;
				a[t]=1;
			}
		}
	for(n=0;n<k;n++)
	{
		printf("%05d",b[n]);
		if(n!=k-1)
		cout<<" ";
	}
	if(!k)
		cout<<"No one is handsome\n";
} 

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值