Description
蒜头君写程序时习惯用蛇形命名法 (snake case) 为变量起名字,即用下划线将单词连接起来,例如:file_name、 line_number。
花椰妹写程序时习惯用驼峰命名法 (camel case) 为变量起名字,即第一个单词首字母小写,后面单词首字母大写,例如:fileName、lineNumber。
为了风格统一,他们决定邀请公正的第三方来编写一个转换程序,可以把一种命名法的变量名转换为另一种命名法的变量名。
你能帮助他们解决这一难题吗?
Input
第一行包含一个整数N,表示测试数据的组数。(1≤N≤10)
以下N行每行包含一个以某种命名法命名的变量名,长度不超过100。
输入保证组成变量名的单词只包含小写字母。
Output
对于每组数据,输出使用另一种命名法时对应的变量名。
Sample Input 1
2 file_name lineNumber
Sample Output 1
fileName line_number
Hint
考虑变量名最后一个字符是下划线的情况
Code
#include<stdio.h>
#include<string.h>
int main()
{
char str[10][100]= {0},str1[10][200]= {0};//存在都大写情况,开两倍
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
int k=0,len=0;
scanf("%s",str[i]);
len=strlen(str[i]);
for (int j = 0; j < len; j++)
{
if (str[i][j] >= 'A'&&str[i][j] <= 'Z')
{
str1[i][k++] = '_';
str1[i][k++] = str[i][j] + 32;
}
else if (str[i][j] == '_' && (str[i][j+1] >= 'a'&&str[i][j+1] <= 'z'))
{
str1[i][k++] = str[i][j+1] - 32;
j++;//从下划线的下一个字母开始判断
}
else
str1[i][k++] = str[i][j];
}
}
for(int i=0; i<n; i++)
printf("%s\n",str1[i]);
return 0;
}