Problem Type: String
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<ctype.h>
#include<algorithm>
//#include<string>
using namespace std;
int main()
{
char ch[10000],des[10000] ,a[2]="#";
int len,i,k,l1=0,q,p;
int j;
string s ="";
while(gets(ch))
{
j=0;
if(strcmp(ch,a)==0)
break;
len = strlen(ch);
for(i=0; i<len; i++)
{
if(l1!=0)
{
for(k=0; ; k++)
{
if(isalpha(ch[k]))
s=s+ch[k];
if(ch[k+1]==' ')
break;
}
i=k;
l1=s.length();
for(q=0;q<l1;q++)
{
cout << s[q] ;
}
cout <<endl;
l1=0;
s="";
}
else if(isalpha(ch[i])||ch[i]==' ')
{
des[j]=ch[i];
j++;
}
else if(ch[i]=='-')
{
while(true)
{
if(isalpha(des[j]))
s=s+des[j];
if(des[j-1]==' ')
{
break;
}
j--;
}
l1=s.length();
reverse(s.begin(),s.end());
}
}
des[j]='\0';
printf("%s\n",des);
memset(ch,'\0',sizeof(ch));
memset(des,'\0',sizeof(des));
}
}
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<ctype.h>
#include<algorithm>
//#include<string>
using namespace std;
int main()
{
char ch[10000],des[10000] ,a[2]="#";
int len,i,k,l1=0,q,p;
int j;
string s ="";
while(gets(ch))
{
j=0;
if(strcmp(ch,a)==0)
break;
len = strlen(ch);
for(i=0; i<len; i++)
{
if(l1!=0)
{
for(k=0; ; k++)
{
if(isalpha(ch[k]))
s=s+ch[k];
if(ch[k+1]==' ')
break;
}
i=k;
l1=s.length();
for(q=0;q<l1;q++)
{
cout << s[q] ;
}
cout <<endl;
l1=0;
s="";
}
else if(isalpha(ch[i])||ch[i]==' ')
{
des[j]=ch[i];
j++;
}
else if(ch[i]=='-')
{
while(true)
{
if(isalpha(des[j]))
s=s+des[j];
if(des[j-1]==' ')
{
break;
}
j--;
}
l1=s.length();
reverse(s.begin(),s.end());
}
}
des[j]='\0';
printf("%s\n",des);
memset(ch,'\0',sizeof(ch));
memset(des,'\0',sizeof(des));
}
}
No comments:
Post a Comment