여기
void truncate(char *str, int inLen){
int len=strlen(str);
char *newstr;
newstr=(char *)malloc(inLen*sizeof(char));
if(inLen>len)
strcpy(newstr,str);
else{
strncpy(newstr,str,inLen);
}
printf("%s",newstr);
}
C++ 솔루션 :
여기
#include<iostream>
#include<string.h>
using namespace std;
void truncate(char *str, int inLen){
int len=strlen(str);
char *newstr=new char[inLen];
if(inLen>len)
strcpy(newstr,str);
else{
strncpy(newstr,str,inLen);
}
cout<<newstr;
}
int main()
{
char str[100];
int inLen;
cin>>inLen;
cin>>str;
truncate(str,inLen);
return 0;
}
파이썬 :
string=input("Enter string")
inLen=int(input("Enter trim length"))
newstring=string[0:inLen]
print(newstring)
는 왜 우리가 당신의 일을 기대합니까? –
스택 오버플로에 오신 것을 환영합니다. 이것은 숙제 완료 서비스가 아닙니다. 강사가 우리가 아니라 과제를 주었고, 당신은 자신의 일을해야 할 것입니다. 시작할 수 없다면 교사에게 도움을 요청하십시오. 그들은 당신을 가르치기 위해 돈을 받고 있습니다. [help/on-topic]은 숙제 도움을 요청하는 질문 **에는 문제를 해결하기 위해 지금까지 해 온 작업의 요약과 문제 해결에 대한 설명이 포함되어야합니다. *** 행운을 빕니다. –
어떤 언어로이 작업을 수행하려고합니까? – jhpratt