第一期练习题test5

#include "pch.h"
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int a,n=0;  //n记录a的位数
	cin >> a;
	int f = a;
	int p[5];
	int k = 1;
	for (;f != 0; )
	{
		f = f / 10;
		n++;
	}
	int i;
	for ( i= 1; i<=n; ++i) //例 45411054
	{
		int t = pow(10, i);
		int x = (a %t-a%(t/10))/(t/10);
		if (x == 5) 
		{
			p[k-1] = a % (t / 10);
			a = a / t;
			cout << "i=" << i << endl;
			n = n - i;
			cout << "n=" << n<<endl;
			i = 1;
			++k;//k表示被分成的组数
		} 
		cout << "x=" << x << endl;
	}
	for ( i = 0; i < k; ++i)
	{
		cout << p[i] << ' ';
	}

}
阅读更多

没有更多推荐了,返回首页