zoukankan      html  css  js  c++  java
  • 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代码:
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     int p,t,r,k;char tmp[25],str[200];
     5     while(cin>>p){
     6         for(int i=1;i<=p;++i){
     7             memset(str,'',sizeof(str));
     8             cin>>t>>r>>tmp;k=0;
     9             for(int j=0;tmp[j]!='';++j)
    10                 for(int g=1;g<=r;++g)//每次填充r个相同的字符
    11                     str[k++]=tmp[j];
    12             cout<<t<<' '<<str<<endl;
    13         }
    14     }
    15     return 0;
    16 }
  • 相关阅读:
    Mac查看与修改系统默认shell
    nginx经验分享
    如何将MAC的 Terminal 行首变得清爽简洁一点?
    关于Promise详解
    关于Webpack详述系列文章 (第四篇)
    关于Webpack详述系列文章 (第三篇)
    关于Webpack详述系列文章 (第二篇)
    关于Webpack详述系列文章 (第一篇)
    关于回调函数和回调函数常出现的问题
    原生JS使用Blob导出csv文件
  • 原文地址:https://www.cnblogs.com/acgoto/p/9235946.html
Copyright © 2011-2022 走看看