Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现 A--A Repeating Characters
2015-04-08 08:36
381 查看
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 repeated R times.That is,R copies of the first character of S,followed by R copies of the second character of S,andso on.Valid characters for S are the QR
Code “alphanumeric” characters:
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ$%*+-. /:
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 single line of input consisting of the data set number N,followed by a space,followed by the repeat count R,(1<=R<=8),followedby 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 line of output. It contains the data set number,N, followed by a single apace 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 /////HHHHHTTTTTPPPPP
HINT
AC代码:#include <iostream> #include <cstring> using namespace std; void fun(string s,char output[],int num){ int i,count=0,j,m; for(i=0;i<(m=s.length());i++){ j=0; while(j<num){ output[count++]=s[i]; j++; } } i=0; while(i<count) cout<<output[i++]; cout<<'\12'; } int main(){ int n,i,num,a; string s; char output[1000]; cin>>n; i=0; while(i<n){ cin>>a; cin>>num; cin>>s; cout<<a<<" "; fun(s,output,num); i++; } return 0; }
运行结果:
相关文章推荐
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现Problem H: H-Sum 3s
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现F-A Simple Question
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现 B--Faultfinding
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现Problem C: C-Z型变换
- 程序设计模式之"监听器模型"
- acm/icpc中国 辽宁省第二届大学生程序设计竞赛结束了
- 利用ftp服务程序本身设计的"缺陷"取得最高权限
- 第二届"春回燕归 浙籍精英峰会"见闻
- 身份证校验 如果让你设计个程序,用什么变量保存身份证号码呢?长整数可以吗?不可以! 因为有人的身份证最后一位是"X"
- "某个程序安装已在安装计算机上创建挂起的文件操作" 解决办法
- 升级IE弹出"以前的安装有尚未完成的操作,需要重新启动。建议在运行Internet Explorer安装程序之前重新启动计算机。现在安装程序将关闭"
- "分段好啊分段好"求最大M个数的程序 (上)2006-07-18
- "某个程序安装已在安装计算机上创建挂起的文件操作" 解决办法 另解
- "某个程序安装已在安装计算机上创建挂起的文件操作" 解决办法 另解
- 使用VS2003创建WEB程序的时候出现"AutoMation服务器不能创建对象"错误
- 未能在"设计"视图中打开.在""块中,以不同方式将值括起来的解决方案汇总
- 未能在"设计"视图中打开.在""块中,以不同方式将值括起来的解决方案汇总
- 打开文件->选择程序 出现"拒绝访问"
- 设计模式-OOD的设计原则(5)-"合成聚合复用原则"
- 安装Visual Studio 6的"Error Lauching acmboot.exe"问题解决方法