Phone numbers
Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.
Input
The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.
Output
Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.
Example
6
549871
54-98-71
7
1198733
11-987-33 代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath> using namespace std; int main()
{
int n;
char s[];
scanf("%d",&n);
scanf("%s",s);
int d = n % ;
for(int i = ;i < n;i += )
{
if(i)putchar('-');
if(d > )printf("%c%c%c",s[i ++],s[i + ],s[i + ]);
else printf("%c%c",s[i],s[i + ]);
d --;
}
}
Phone numbers的更多相关文章
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
- [LeetCode] Compare Version Numbers 版本比较
Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1 &l ...
- [LeetCode] Sum Root to Leaf Numbers 求根到叶节点数字之和
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
随机推荐
- IDEA中文出现乱码解决
转自:http://lcl088005.iteye.com/blog/2284696 我是个idea的忠实用户,新公司的项目都是用eclipse做的,通过svn拉下代码后发现,注释的内容里,中文内容都 ...
- ZOJ 3958 Cooking Competition 【水】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3958 AC代码 #include <cstdio> ...
- 写给后端程序员的HTTP缓存原理介绍--怎样决定一个资源的Cache-Control策略呢
通过Internet获取资源既缓慢,成本又高.为此,Http协议里包含了控制缓存的部分,以使Http客户端可以缓存和重用以前获 取的资源,从而优化性能,提升体验.虽然Http中关于缓存控制的部分,随着 ...
- jQuery带缩略图焦点图插件
在线演示 本地下载
- 大话设计模式之PHP篇 - 观察者模式
定义观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象,这个主题对象在状态发生改变时,会通知所有观察者对象,使他们能够自动更新自己. <?php /*主题类或称为通知类 ...
- OC_NSFileManager
案例1:通过文件扩展名进行搜索文件 NSFileManager *manager = [NSFileManager defaultManager]; /* 在Mac OS X系统有一个代表主目录的速 ...
- python实现免密码登录lunx服务器
import paramikoimport oshostname='192.168.76.10'username='root'# password='123456'ssh=paramiko.SSHCl ...
- WebUploader API文档
Web Uploader内部类的详细说明,以下提及的功能类,都可以在WebUploader这个变量中访问到. As you know, Web Uploader的每个文件都是用过AMD规范中的defi ...
- Centos6.5安装Mysql5.6.10
1. 先卸载掉老版本的mysql(linux严格区分大小写,查找的时候加上-i参数,和mysql相关的全部要卸) [root@liuchao ~]# rpm -qa | grep -i mysqlMy ...
- 2017 GDS 全球域名大会7月7日举行
2017年域名行业历经产业波澜,引发域名圈内对域名价值衍生及商业模式的探索.如今无论域名注册商.域名交易平台.域名拍卖平台都在寻找更好的商业模式,开启域名行业新航向. 7月,在中国域名之都厦门将掀起一 ...