PAT基础编程题目-7-3 逆序的三位数

PAT基础编程题目-7-3 逆序的三位数

题目详情

题目地址:https://pintia.cn/problem-sets/14/problems/783

解答

C语言版

#include<stdio.h>
int main() {
   
	int array[3];
	int number;
	scanf("%d", &number);
	for (int i = 0; i < 3; i++)
	{
   
		array[i] = number % 10;
		number = number / 10;
	}
	for (int j = 0; j < 3; j++)
	{
   
		if (array[j] || (array[1]==0 && array[0]!=0) )
			printf("%d", array[j]);
	}
	return 0;
}

C++版

#include<iostream>
using namespace std;
int main() {
   
	int array[3];
	int number;
	cin >> number;
	for (int i = 0; i < 3; i++)
	{
   
		array[i] = number % 10;
		number = number / 10;
	}
	for (int j = 0; j < 3; j++)
	{
   
		if (array[j] || (array[1] == 0 && array[0] != 0))
			cout << array[j];
	}
	return 0;
}

Java版

import java.util.Scanner;
public class Main{
   

	public static void main(String[] args) {
   
		int number = 0;
		int [] array = new int[3];
		Scanner scanner = new Scanner(System.in);
		if(scanner.hasNext()) {
   
			number = scanner.nextInt();
		}
		scanner.close();
		for (int i = 0; i < array.length; i++) {
   
			array[i] = number%10;
			number = number/10;
		}
		for (int j = 0; j < array.length; j++) {
   
			if (array[j]!=0 || (array[1]==0 && array[0]!=0)) {
   
				System.out.print(array[j]);
			}
		}
	}

}

创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!

全部评论

相关推荐

喜欢走神的孤勇者练习时长两年半:池是池,发是发,我曾池,我现黑
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务