C + + and JavaTime
Limit: 1000MS
Memory Limit:65536KB
64bit IO Format:%lld &%llu< /c11>
Description
According to the Java naming convention, the naming convention for variable names consisting of multiple words is: The first word begins with a lowercase letter, the remaining words begin with an uppercase letter, and the words do not have any separators between the words, except for the letters with the first letter of the word being lowercase. For example: Name, MyName. C + + is named with all lowercase letters, and "_" is used between words and words as delimiters. For example: Name, My_name.
Your job is to write a program that converts the name of a variable named by C + + to a Java naming method.
Input
The input contains multiple sets of test data.
Each set of data is a row of strings (the string length does not exceed 100).
Output
For each set of test data, output the converted string. Note: If the input string does not conform to the C + + naming convention, output "Error" (without quotation marks).
Sample Input
My_namemyname
Sample Output
Mynameerror
#include <stdio.h>#include<string.h>#include<string.h>intMain () {Chars[ +], t[ +]; intLen, I, K, flag; while(Gets (s)! =NULL) {k=0; Flag=0; memset (T,0,sizeof(t)); Len=strlen (s); for(i=0; i<len; i++)//whether to name a legitimate C + + { if(s[i]<'a'|| S[i]>'Z') { if(s[i]=='_') { if(s[0]=='_'|| s[len-1]=='_'|| s[i+1]=='_') {printf ("error\n"); Flag=1; Break; } } Else{printf ("error\n"); Flag=1; Break; } } } if(flag)Continue; for(i=0; i<len; i++)//if the legal changes to the Java naming form { if(s[i]=='_') ; Else if(s[i]>='a'&& s[i]<='Z') { if(s[i-1]=='_') T[k+ +] = s[i]- +; Elset[k++] =S[i]; }} printf ("%s\n", T); } return 0;}
View Code
C + + and Java (analog)