0
点赞
收藏
分享

微信扫一扫

洛谷 P1307

我阿霆哥 2022-01-10 阅读 131

数组方法

#include <bits/stdc++.h>

using namespace std;

int main()
{
	long long int n, a[10], sum = 0, x;
	cin >> n;
	long long int b = n;
	long long int i = 1;
	if (b < 0)
	{
		cout << "-";
		b = -b;
	}
	if (b == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	while (b != 0)
	{
		int c = b % 10;
		b = b / 10;
		a[i] = c;
		i++;
		sum++;
	}
	if (a[1] == 0)
		x = 1;
	for (int j = 1; j <= sum; ++j)
	{
		if (x == j && a[j] == 0)
		{
			x++;
			continue;
		}
		else
			cout << a[j];
	}
	return 0;
}

数字取余数

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m = 0;
	cin >> n;
	while (n != 0)
	{
		m = m * 10 + n % 10;
		n = n / 10;
	}
	cout << m << endl;
	return 0;
}
举报

相关推荐

洛谷p1135

洛谷p1551

洛谷P1309

P1217(洛谷)

洛谷p1443

洛谷P1090

洛谷P2084

洛谷 P1001

0 条评论