ACM_Repeating Characters
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的更多相关文章
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [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 ...
- [LeetCode] Sort Characters By Frequency 根据字符出现频率排序
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
随机推荐
- Mac安装Qt出现错误Could not resolve SDK Path for 'macosx'
Qt 5.8 + Mac 10.14 qdevice.pri文件里没有网上说的那行应该改的代码,自己写上这句话也没有解决问题 最终解决方案: 在命令行输入:sudo xcode-select -s ...
- 斯特林公式 hdu1018
杭电上面1018>>点击测试<< 思路:当问到阶乘的值时候,用万进制来写:但是问阶乘值的位数的时候,就可以用斯特林公式了 log10(2*pi*n)/2+n*log10(n/e ...
- Python基础(四) 基础拾遗、数据类型进阶
一.基础拾遗 (一).变量作用域 外层变量,可以被内层变量直接调用:内层变量,无法被外层变量使用.这种说法在其它语言中适用,在python中除了栈以外,正常的变量作用域,只要执行声明并在内存中存在,该 ...
- .NET-高并发及限流方案
前言:高并发对我们来说应该都不陌生,特别想淘宝秒杀,竞价等等,使用的非常多,如何在高并发的情况下,使用限流,保证业务的进行呢.以下是一个实例,不喜勿喷! 总体思路: 1. 用一个环形来代表通过的请求 ...
- Thinkphp 批量更新方法 saveALL
批量更新只适用于一个字段的更新,原理是用自定义函数拼接sql语句,然后再执行sql语句. //数据 $data[] = array('id'=>1,'value'=>value1); $d ...
- Java基础学习总结(87)——坚持写Java等技术类博客的好处
1.加深对技术点的理解 每天写博客,可以加深对技术点的理解,假如工作中,对某个技术点运用的不熟,当你通过博客的形式写出来,这个过程中,遇到不懂的知识点,你就会查阅相关的资料,弄明白他. 2.自己日后用 ...
- PatentTips - Hamming distance comparison
BACKGROUND INFORMATION In a typical data processing environment, data may be transmitted in multiple ...
- kendo Cannot read property 'call' of undefined
造成这个错误的原因是在 必须有id的定义
- 《WF in 24 Hours》读书笔记 - Hour 1 - Understanding Windows Workflow Foundation
1.1 Hour 1 - Understanding Windows Workflow Foundation 1.1.1 What workflow is in general A workflo ...
- 运行Java -jar somefile.jar时发生了什么(二)
(6)Java.c中的LoadMainClass 位置jdk/src/share/bin/java.c 该方法负责载入main函数所在的类. 该方法首先载入sun.launcher.LauncherH ...