[YTU]_2781( 重复字符串)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_2781( 重复字符串)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
輸入一個字符串,將其重復若干次,例如,輸入goal和5,得到的就是球迷的歡呼:goalgoalgoalgoalgoal。
不急著歡呼,先補充完整下面的程序。還需要注意的是,給出的程序段中,還藏著一個小Bug,需要你將其改過來。
#include <iostream>
#include <cstdio>
using namespace std;
void strcopy(char*,char*,int);
int main( )
{
???? char str1[80];
???? char str2[80];
???? int n;
???? gets(str1);
???? cin>>n;
???? strcopy(str2,str1,4);
???? cout<<str2<<endl;
???? return 0;
}
Input
一個待重復的字符串
重復的次數
Output
重復后的文字
Sample Input
goal 5Sample Output
goalgoalgoalgoalgoal#include <iostream> #include <cstdio> #include <cstring> using namespace std; void strcopy(char*,char*,int); int main() {char str1[80],str2[80];int n;gets(str1);cin>>n;strcopy(str2,str1,n);cout<<str2<<endl;return 0; } void strcopy(char*str2,char*str1,int n) {int i;str2[0]='\0';for(i=0;i<n;i++){strcat(str2,str1);} }總結
以上是生活随笔為你收集整理的[YTU]_2781( 重复字符串)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_2803( 字符串中小写改大
- 下一篇: [YTU]_2800( 逗逗泡泡的保密电