PAT基础编程题目-7-3 逆序的三位数
PAT基础编程题目-7-3 逆序的三位数
题目详情
解答
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]);
}
}
}
}
创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!