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 ...
随机推荐
- String replaceAll 正则注意事项及特殊用法(xjl456852原创)
我们知道String replaceAll(参数a, 参数b) 参数a是需要些正则表达式的. 但是今天试了试,发现参数b也有一些其它特性. 查看源码后,发现有些特性是平时不怎么用的.下面我来介绍一下这 ...
- Navigator的学习
Navigator 对象包含有关浏览器的信息.注释:没有应用于 navigator 对象的公开标准,不过所有浏览器都支持该对象. 我感觉需要看什么属性和方法,直接输出这个navigator,然 ...
- json转换时区问题-------前端展示时间少8小时--解决方法
在application配置文件中加如下: spring.jackson.time-zone=GMT+8
- 洛谷—— P1419 寻找段落
https://www.luogu.org/problem/show?pid=1419 题目描述 给定一个长度为n的序列a_i,定义a[i]为第i个元素的价值.现在需要找出序列中最有价值的“段落”.段 ...
- tomcat服务器配置把Http协议强制转化为Https
1)在命令提示符窗口,进入Tomcat目录,执行以下命令: keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass ...
- HTTP状态码图示
这里总结下我们日常开发中常用的HTTP状态码,分享一个老外对HTTP状态码形象化用图片表示的网站:https://http.cat/ 总结如下: 表示服务器已经接收到了请求头,并且客户端应该继续发送请 ...
- BMP的图像处理
近期碰到了一个问题将图片缩放: 进行了整理发现位图一些主要的结构能够进行整理,得出下面图表: 进行图片缩放的时候会进行一些处理(最临近差值法): 详细的代码例如以下: #include <std ...
- leetCode 89.Gray Code (格雷码) 解题思路和方法
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- Python3基础(七) I/O操作
一个程序可以从键盘读取输入,也可以从文件读取输入:而程序的结果可以输出到屏幕上,也可以保存到文件中便于以后使用.本文介绍Python中最基本的I/O函数. 一.控制台I/O 读取键盘输入 内置函数in ...
- 使用NDIS驱动监測以太网络活动
转载自: http://blog.csdn.net/ddtpower/article/details/656687 本论文提供了NDIS的主要的理解,应用程序怎样与驱动程序交互.发挥驱动程序最佳性 ...