#include
#include
#include
#include
void nhap(char str[])
{
printf("Nhap mot chuoi: \n\t");
gets(str);
}
void xuat(char str[])
{
printf("\nChuoi: \n\t");
puts(str);
}
void chuanhoa(char *str)
{
char *p;
while(str[0]==' ')
strcpy(str,str+1);
while(str[strlen(str)-1]==' ')
str[strlen(str)-1]='';
do
{
p=strstr(str," ");
if(p!=NULL) strcpy(p,p+1);
}while(p!=NULL);
strlwr(str);
str[0]=toupper(str[0]);
for(int i=1;i<strlen(str);i++)
if(str[i]!=0 && str[i-1]==' ')
str[i]=toupper(str[i]);
printf("\nChuoi sau khi chuan hoa:\n\t");
puts(str);
}
int demtieng(char *str)
{
int d=1,i;
for(i=0;i<strlen(str);i++)
if(str[i]==' ')
d++;
return d;
}
int demslxhktu(char *p,char c)
{
int d=0;
for(int j=0;j<strlen(p);j++)
if(p[j]==c)
d++;
return d;
}
void dem(char *p)
{
int i,j;
for(i=0;i=0;j--)
if(p[j]==p[i]) break;
if(j<0)
{
int k=demslxhktu(p,p[i]);
printf("\n%c : %d",p[i],k);
}
}
}
void main()
{
char str[100];
nhap(str);
xuat(str);
chuanhoa(str);
printf("Trong chuoi co %d tieng.",demtieng(str));
dem(str);
getch();
}
No comments:
Post a Comment