PAT(Basic)-1006.换个格式输出整数(15)
来源:互联网 发布:大数据互联网龙头企业 编辑:程序博客网 时间:2024/05/01 16:45
1006. 换个格式输出整数 (15)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数。例如234应该被输出为BBSSS1234,因为它有2个“百”、3个“十”、以及个位的4。
输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000)。
输出格式:每个测试用例的输出占一行,用规定的格式输出n。
输入样例1:234输出样例1:
BBSSS1234输入样例2:
23输出样例2:
SS123程序代码(Java)import java.util.Scanner;public class P1006 {public static void main(String[] args){Scanner input=new Scanner(System.in);int n=input.nextInt();if(n<10)f1(n);else if(n<100)f2(n);elsef3(n);}static void f1(int n){for(int i=1;i<=n;i++)System.out.print(i);}static void f2(int n){int s=n/10;int g=n%10;for(int i=0;i<s;i++)System.out.print('S');f1(g);}static void f3(int n){int b=n/100;for(int i=0;i<b;i++)System.out.print('B');f2(n-100*b);}}
尊重别人的劳动成果,转载请注明来源。代码优化的问题,大牛们请多多指点。
0 0
- PAT Basic Level 1006. 换个格式输出整数 (15)
- PAT BASIC PRACTICE: 1006. 换个格式输出整数 (15)
- PAT BASIC LEVEL 1006. 换个格式输出整数 (15)
- PAT(Basic)-1006.换个格式输出整数(15)
- PAT (Basic Level) Practise (中文)1006. 换个格式输出整数 (15)
- PAT (Basic Level) Practise (中文)1006. 换个格式输出整数 (15) C语言
- PAT Basic 1006. 换个格式输出整数 (15)(C语言实现)
- PAT (Basic Level) Practise (中文) 1006. 换个格式输出整数 (15)
- PAT (Basic Level) Practise (中文)1006. 换个格式输出整数 (15)
- 【PAT】(乙级)1006. 换个格式输出整数 (15)
- PAT(乙)-1006. 换个格式输出整数 (15)
- PAT(乙) 1006. 换个格式输出整数 (15)
- PAT-乙级 1006.换个格式输出整数(15)
- PAT (Basic Level) Practise (中文) —— 1006. 换个格式输出整数
- 1006. 换个格式输出整数(PAT Basic)
- PAT (Basic Level)1006. 换个格式输出整数
- PAT.Basic level.T.1006.换个格式输出整数
- pat(B) 1006. 换个格式输出整数
- dijkstra 昂贵的聘礼 poj1062
- ios枷锁解锁
- VMware安装windows XP OS 虚拟机时常见的问题
- MongoDBm基本概念的分析
- svn使用简介
- PAT(Basic)-1006.换个格式输出整数(15)
- OpenGL DC RC关系
- 【Leetcode】Remove Nth Node From End of List
- 一个用于灰度标定的matlab函数
- HDOJ 2955 Robberies 【0 1背包】
- Ubuntu14.04 下 OpenCV2.4.9 编译
- 数据结构例程——分块查找
- Can’t install ia32-libs and ia32-libs-multiarch: how to fix it
- shell脚本