/*
串的处理
在实际的开发工作中,对字符串的处理是最常见的编程任务。本题目即是要求程序对用户输入的串进行处理。具体规则如下:
1. 把每个单词的首字母变为大写。
2. 把数字与字母之间用下划线字符(_)分开,使得更清晰
3. 把单词中间有多个空格的调整为1个空格。
例如:
用户输入:
you and me what cpp2005program
则程序输出:
You And Me What Cpp_2005_program
*/
#include<stdio.h>
#include<string>
using namespace std;
//' '为空格字符 ''为空字符
void Upper(char * x)
{
if(x[0]>=97 && x[0]<=122) x[0]=x[0]-32;
for(int i=0;i<strlen(x);i++)
{
if(x[i]==' ' && x[i+1]>=97 && x[i+1]<=122)
x[i+1]=x[i+1]-32;
}
}
void deblank(char * x)
{
char dst[200];
int i=0,flag=0;
int dst_index=0;
while(x[i]!='')
{
if(x[i]!=' ')
{
flag=1;
dst[dst_index++]=x[i];
}
else{
if(flag)
{
dst[dst_index++]=' ';
flag=0;
}
}
i++;
}
dst[dst_index]='';
strcpy(x,dst);
}
void line(char * x)
{
char dst[200];
int i=0,flag=0;
int dst_index=0;
while(x[i]!='')
{
if(( x[i]>=97 && x[i]<=122)
&&( x[i+1]>=48 && x[i+1]<=58)){
// if(!flag)
// {
dst[dst_index++]=x[i];
dst[dst_index++]='_';
// flag=0;
// }
}
else if(( x[i]>=48 && x[i]<=58)
&&( x[i+1]>=97 && x[i+1]<=122))
{
dst[dst_index++]=x[i];
dst[dst_index++]='_';
// dst[dst_index++]=x[i];
}
else
{
//flag=1;
dst[dst_index++]=x[i];
}
i++;
}
dst[dst_index]='';
strcpy(x,dst);
}
int main()
{
char a[100];
gets(a);
Upper(a);
deblank(a);
line(a);
puts(a);
return 0;
}