I have to remove all punctuation marks from a string and if there is only 1 punctuation mark there should be space (example rrr.rr should be rrr rr) and if there is more then 1 punctuation mark then but a number(example rrr.,..rr should be rrr4rr)
This examples is good:
input jks6X7hs__xXxJK!jsX...YKY7,;,shhhXsHXSh__!..x
output: jks6X7hs2xXxJK jsX3YKY73shhhXsHXSh5x
But these examples wont work properly
input: __
Output: 2
input: _X_X_X_X_
output: X X X X
And this is my code:
for(i=0;i<n;i++)
{
if(!(p[i]>='0' && p[i]<='9') && !(p[i]>='a' && p[i]<='z') && !(p[i]>='A' && p[i]<='Z')) {
counter=0;
while(!(p[i]>='0' && p[i]<='9') && !(p[i]>='a' && p[i]<='z') && !(p[i]>='A' && p[i]<='Z'))
{
i++;
counter++;
}
i--;
if(counter==1)
{
p[increment++]=' ';
}
else{
p[increment++]=counter+'0';
}
}
else{
p[increment++]=p[i];
}
Aucun commentaire:
Enregistrer un commentaire