Repeating Characters

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

For this problem, you will write a program that takes a string of characters, S, and creates a new string of characters, T, with each character repaeated R times. That is, R copies of the first character of S, followed by R copies of the second character of S, and so on. Valid characters for S are the QR Code "alphanumeric" characters:

0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z $ % * + - . / : 

Input:

The first line of input contains a single integer P,(1 <= P <= 1000), which is the number of data sets that follow. Each data set is a single ling of input consisting of the data set number N, followed by a space, followed by the repeat count R, (1 <= R <= 8), followed by a space , followed by the string S. The length of string S will always be at least one and no more than 20 characters. All the characters will be from the set of characters shown above.

Output:

For each data set there is one ling of output. It contains the data set number, N, followed by a single space which is then followed by the new string T, which is made of each character in S repeated R times.

Sample Input:

2
1 3 ABC
2 5 /HTP

Sample Output:

1 AAABBBCCC
2 /////HHHHHTTTTTTPPPPP
解题思路:将每个字符输出r次即可,水过!
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int main(){
int p,t,r,k;char tmp[],str[];
while(cin>>p){
for(int i=;i<=p;++i){
memset(str,'\0',sizeof(str));
cin>>t>>r>>tmp;k=;
for(int j=;tmp[j]!='\0';++j)
for(int g=;g<=r;++g)//每次填充r个相同的字符
str[k++]=tmp[j];
cout<<t<<' '<<str<<endl;
}
}
return ;
}

ACM_Repeating Characters的更多相关文章

  1. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  2. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  3. [LeetCode] Sort Characters By Frequency 根据字符出现频率排序

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

  4. [LeetCode] Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串

    Given a string, find the length of the longest substring T that contains at most k distinct characte ...

  5. [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串

    Given a string S, find the length of the longest substring T that contains at most two distinct char ...

  6. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  7. [LeetCode] Read N Characters Given Read4 用Read4来读取N个字符

    The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actua ...

  8. [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  9. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

随机推荐

  1. array copy rotate in Pointwise

    goal: # # Copyright 2010 (c) Pointwise, Inc. # All rights reserved. # # This sample Pointwise script ...

  2. node-sass 安装失败

    安装 npm install 时偶尔遇到报错:没有安装python或node-sass 安装失败的问题,百度之后发现是被墙了,但根据百度的方法换了淘宝镜像和用了vpn都安装失败, 原因可能是没有卸载之 ...

  3. redis学习——数据类型

    一.内容简介 Redis不仅仅是简单的key-value 存储器,同时也是一种data structures server.传统的key-value是指支持使用一个key字符串来索引value字符串的 ...

  4. 仪仗队(codevs 2296)

    题目描述 Description 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来 ...

  5. J2EE 课件3 JSP标记

    •JSP标记包括指令标记.动作标记和自定义标记.其中自定义标记主要讲述与Tag文件有关的Tag标记    1.指令标记page page 指令用来定义整个JSP页面的一些属性和这些属性的值,属性值用单 ...

  6. 局域网部署docker--从无到有创建自己的docker私有仓库

    因为GFW的关系.国内用户在使用docker的时候,pull一个主要的镜像都拉下来.更不用说使用官方的index镜像了.差点放弃使用docker了,google了一圈.总算找到办法. 第一步:安装do ...

  7. CocoaPods pod instal慢、卡住解决方法

    CocoaPods pod install慢.卡住解决方法 近期使用CocoaPods来加入第三方类库,不管是运行pod install还是pod update都卡在了Analyzing depend ...

  8. Live555研究之中的一个 源码编译

                                                Live555研究之中的一个 源代码编译 Live555 是一个为流媒体提供解决方式的跨平台的C++开源项目,它 ...

  9. POJ 1741 Tree 树形DP(分治)

    链接:id=1741">http://poj.org/problem?id=1741 题意:给出一棵树,节点数为N(N<=10000),给出N-1条边的两点和权值,给出数值k,问 ...

  10. 数据库html 数据的分句

    Python 中文分句 - CSDN博客 https://blog.csdn.net/laoyaotask/article/details/9260263 # 设置分句的标志符号:可以根据实际需要进行 ...