一、题目链接
http://noi.openjudge.cn/ch0103/13/
二、解题思路
◎ 对于三位整数n:n%10可以得到个位数;(n/10)%10可以得到十位数;n/100可以得到百位数;
三、实施步骤
◎ 首先,定义并输入int类型的整数n,代表待处理的三位整数;
◎ 其次,定义并输入三个int类型的整数t1、t2、t3,分别代表个位数、十位数、百位数;
◎ 然后,令t1=n%10,t2=(n/10)%10,t3=n/100;
◎ 最后,通过输出语句,输出t1、t2、t3。
四、Java程序
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int t1 = n % 10;
int t2 = (n / 10) % 10;
int t3 = n / 100;
System.out.print("" + t1 + t2 + t3);
}
}
五、C++程序
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int t1 = n % 10;
int t2 = (n / 10) % 10;
int t3 = n / 100;
cout << t1 << t2 << t3;
return 0;
}