将第一行中含有第二行中“23”的数输出并排序

.输入一行数字:123 423 5645 875 186523

在输入第二行:23

将第一行中含有第二行中“23”的数输出并排序
结果即:123 423 186523


思路: .依据第二行输入的数,每次除以这个数的的 上限 (23 -- 100, 123-- 1000)取余数 比较 ,不同就再 除10,继续。

如果存在那 放入一个数组中。




#include<iostream>
#include<algorithm>
using namespace std;

int  find(int * ,int ,int); //查找出处带有第二行的个数,并将其放在前几个位置

int main()
{
	int arr[10],i =0;
	char c ='0';
	while (c !='\n')
	{
		cin>> arr[i];
		i++;
		cin.get(c); //处理单行输出的enter,
	}
	int number;
	cin>> number;
	int count =find (arr,i,number);
	sort(arr,arr+count); //排序 
	for(int i =0 ;i <count ; i++)//输出 
		cout<<arr[i]<<ends;
}
int  find (int * arr,int  n, int number)
{
	int max =10;
	int tem =number ;
	while (tem /= 10)//查找出第二行对应的上限  53-> 100,123->1000
		max *= 10;
	int count = 0;
	for(int dex = 0 ;dex < n ;dex++){
		tem= arr[dex];
		while( tem )//判断这个数是否包含要查找的书,如果是统计个数,并且交换位置
		{
			if (tem % max == number){
				
				swap(arr[count],arr[dex]);
				count++;
				break;
			}
			else
				tem /=10;
		}
	}
	return count;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值