Hi,
Anyone have test cases of this problem?
What is the output when the line starts with blanks and have a word of size 73?
Bye,
Sebastiao.
Moderator: Board moderators
A line break in the input may be eliminated in the output, provided it is not at the end of a blank or empty line and is not followed by a space or another line break. If a line break is eliminated, it is replaced by a space.
a
***
ba
bInput (Spaces are replaced by '_') wrote:aaa
_____aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaa
bbbbb______________________________________________________________________
bbbbb
ccccc______________________________________________________________________
_____ccccc
ddddd_____
_____ddddd
eeeee
_____eeeee
fffff_____
fffff
Output wrote:aaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaa_bbbbb
bbbbb_ccccc
_____ccccc
ddddd
_____ddddd
eeeee
_____eeeee
fffff______fffff
#include <iostream>
using namespace std;
bool a=true;
void print(char * linea){
//corregir
int len=72, i, j, k;
for(k=len;k>=0&&linea[k]!=' ';k--);
for(j=k;j>=0&&linea[j]==' ';j--);
for(i=0;i<=j;i++){
cout<<linea[i];
}
if(j<0)
j=0;
len=strlen(linea);
for(i=len-1;i>=0&&linea[i]==' ';i--);
len=i+1;
for(i=k+1, k=0;i<len;i++)
linea[k++]=linea[i];
linea[k]='\0';
if(k>72){
if(a)
{
a=false;
print(linea);
a=true;
return;
}
else{
cout<<endl;
for(;linea[len]==' ';len--);
for(i=j;i<len;i++){
cout<<linea[i];
}
linea[0]='\0';
}
}
cout<<endl;
}
void print2(char * linea, char *linea2){
int len=strlen(linea)-1;
for(;len>=0&&linea[len]==' ';len--);
for(int i=0;i<=len;i++)
cout<<linea[i];
if(linea[0]!='\0')
cout<<endl;
len=strlen(linea2)-1;
for(;len>=0&&linea2[len]==' ';len--);
if(len<=0){
cout<<endl;
linea[0]='\0';
return;
}
strcpy(linea,linea2);
}
int main(int argc, char *argv[])
{
freopen("entrada.in","r",stdin);
freopen("salida.in","w",stdout);
char lSig[400], lAnt[400];
lAnt[0]='\0';
while(gets(lSig)){
if(lSig[0]==0||lSig[0]==' '){
print2(lAnt,lSig);
}
else{
if(lAnt[0]!='\0')
strcat(lAnt, " ");
strcat(lAnt, lSig);
}
if(strlen(lAnt)>72)
print(lAnt);
}
int k,i;
for(k=strlen(lAnt)-1;k>=0&&lAnt[k]==' ';k--);
for(i=0;i<=k;i++)
cout<<lAnt[i];
if(i>0)
cout<<endl;
return 0;
}Users browsing this forum: No registered users and 1 guest