GDUFE ACM-1019 Repeating Characters

题目:http://acm.gdufe.edu.cn/Problem/read/id/1019

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遍。复杂度分析:不算难题,但要用到字符串和循环,对于初学者来说还是有点难度的。

代码:

#include<stdio.h>
int main()
{
int P,N,R,i,j,a,b;
char S[100];
while(scanf("%d",&P)!=EOF)
{
for(b=0;b<P;b++)
{
scanf("%d%d",&N,&R);
scanf("%s",S);
i=0;
printf("%d ",N);
while(S[i]!=‘\0‘)
i=i+1;
for(j=0;j<i;j++)
for(a=1;a<=R;a++)
printf("%c",S[j]);
printf("\n");
}
}
return 0;
}

时间: 2024-08-02 11:02:14

GDUFE ACM-1019 Repeating Characters的相关文章

leetcode4 ---Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst

LeetCode---Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst

LeetCode: Longest Substring Without Repeating Characters 题解

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst

LeetCode3 Longest Substring Without Repeating Characters

题目: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest s

[LeetCode] 3. Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.

LeetCode Problem 3.Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.

LeetCode 3_Longest Substring Without Repeating Characters

题目描述: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest

Leetcode 03 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst

Java for LeetCode 003 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest subst

LeetCode Longest Substring Without Repeating Characters 最长不重复子串

题意:给一字符串,求一个子串的长度,该子串满足所有字符都不重复.字符可能包含标点之类的,不仅仅是字母.按ASCII码算,就有2^8=128个. 思路:从左到右扫每个字符,判断该字符距离上一次出现的距离是多少,若大于max,则更新max.若小于,则不更新.每扫到一个字符就需要更新他的出现位置了.这里边还有个注意点,举例说明: 假如有长为16串 s="arbtbqwecpoiuyca" 当扫到第2个b时,距离上一个b的距离是2:(直接减) 当扫到第2个c时,距离上一个c的距离是6:(直接减