Your task is to find for a given phone number any of its divisions into groups of two or three digit
D - Phone numbers
public static void main(String[] args){
int n,i=0,m=1;
Scanner scan=new Scanner(System.in);
n=scan.nextInt();
char[] s=scan.next().toCharArray();
if(n%2==0){
for(i=0;i<n;i=i+2){
if(i<2){
System.out.printf("%c%c",s[i],s[i+1]);
}
else{//i>=2时
System.out.printf("-%c%c",s[i],s[i+1]);
}
}}
else{//n%2!0时
for(i=0;i<n;i=i+m){
if(i==0){
System.out.printf("%c%c",s[i],s[i+1]);
m=2;
//i=i+2;
}
if(i>=2&&i<n-2){
//for(i=2;i<n-2;i=i+3)
System.out.printf("-%c%c%c",s[i],s[i+1],s[i+2]);
m=3;
//i=i+3;
}
if(i==n-2){
System.out.printf("-%c%c",s[n-2],s[n-1]);
break;
}}
}
}
}
Your task is to find for a given phone number any of its divisions into groups of two or three digit相关推荐
- 机器学习与高维信息检索 - Note 4 - 主成分分析及其现代解释(Principal Component Analysis, PCA)及相关实例
主成分分析及其现代解释 4. 主成分分析及其现代解释 Principal Component Analysis and Its Modern Interpretations 4.1 几何学解释 The ...
- ADPRL - 近似动态规划和强化学习 - Note 5 - Banach Fixed Point Theorem in Dynamic Programming
动态规划中的巴拿赫不动点定理 5. Banach Fixed Point Theorem in Dynamic Programming 5.1 巴拿赫不动点定理定理 (Banach fixed poi ...
- PAT Advanced Level 1010
1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...
- 【linux】top命令详解
1.参数详解 $ top -helpprocps-ng version 3.3.9 Usage:top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s ...
- hive2.3.2安装使用
hive的安装简单一些,使用也比较简单,基础hadoop搭建好之后,只要初始化一些目录和数据库就好了 安装需要做几件事: 1.设立一个数据源作为元数据存储的地方,默认是derby内嵌数据库,不过不允许 ...
- SOJ 8064 Whack the Groundhog
Description You are playing the game 'Whack the Groundhog' with your little nephew. Considering your ...
- ural 1014. Product of Digits
1014. Product of Digits Time Limit: 1.0 second Memory Limit: 64 MB Your task is to find the minimal ...
- Java Garbage Collection Basics--转载
原文地址:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Overview Purpose ...
- spark源码解析之基本概念
从两方面来阐述spark的组件,一个是宏观上,一个是微观上. 1. spark组件 要分析spark的源码,首先要了解spark是如何工作的.spark的组件: 了解其工作过程先要了解基本概念 官方罗 ...
最新文章
- 突发!Spring Cloud 爆高危漏洞。。赶紧修复!!
- DARPA人工智能技术研究情况一览
- Java 理论与实践: 修复 Java 内存模型,第 2 部分 (VOLATILE, FINA...
- Spring 学习总结 使用静态工厂创建Bean
- 部署在sae上的servlet程序出现is not a javax.servlet.Servlet 错误
- vfifo控制mig_MIG IP控制DDR3读写测试
- @Validated和@Valid区别:Spring validation验证框架对入参实体进行嵌套验证必须在相应属性(字段)加上@Valid而不是@Validated...
- git 2.30.1最新版本的使用
- php自定义商品属性,php – 可变产品属性:自定义每个显示的单选按钮文本值
- linux用xshell编辑文件,Linux远程管理器xshell和xftp使用教程
- 分子机制研究的五个层次,你的研究在哪个层次--转载
- 腾讯视频《庆余年》再搞超前点播,网友:不是每部剧都叫《陈情令》
- 若依前后端分离项目部署最简单的方式(推荐)
- Python零基础:第一个Python程序“hello world“ 背后的运行你懂了吗?
- 如何使用Log4net创建日志及简单扩展
- tomcat 7下spring 4.x mvc集成websocket以及sockjs完全参考指南(含nginx/https支持)
- maxon电机加速度上不去的原因及解决
- C语言打印图形小妙招
- 异常:java.lang.ArithmeticException
- 数据结构(c语言版) 计算机科学丛书,数据结构与算法分析--C语言描述(原书第2版)(计算机科学丛书)...