fork download
  1.  
  2. #include<stdio.h>
  3.  
  4. char s[101];
  5. char str[205];
  6.  
  7. int main()
  8. {
  9. int i,flag,error_flag,j;
  10. // FILE *file;
  11. //file = fopen("F:\\file.txt","w");
  12.  
  13.  
  14. while(scanf("%s",s)!=EOF){
  15. i = 0 ;
  16. j = 0 ;
  17. error_flag = 0;
  18. while( s[i] != '_' && ( s[i] < 'A' || s[i] > 'Z') && s[i]!='\0'){
  19. str[j] = s[i] ;
  20. i++;
  21. j++;
  22. }
  23. if(s[i]=='\0'){
  24. printf("%s\n",s);
  25. continue;
  26. }
  27.  
  28. if(s[i]>='A' && s[i] <= 'Z' && i==0){
  29. printf("Error!\n");
  30. continue;
  31. }
  32.  
  33. if(s[i]=='_')
  34. flag = 0;
  35. else
  36. flag = 1;
  37.  
  38.  
  39. while(s[i] != '\0'){
  40. if( s[i] == '_'){
  41. if( flag == 1 ){
  42. error_flag = 1;
  43.  
  44. }
  45. else{
  46. str[j] = s[i+1] - 32;
  47. j++;
  48. i += 2;
  49. }
  50. }
  51. else if (s[i] >= 'A' && s[i] <= 'Z'){
  52. if( flag == 0 ){
  53. error_flag = 1;
  54. }
  55. else{
  56. str[j] = '_';
  57. str[j+1] = s[i] + 32;
  58. j += 2;
  59. i++;
  60. }
  61.  
  62. }
  63. else{
  64. str[j] = s[i];
  65. j++;
  66. i++;
  67. }
  68. if (error_flag)
  69. break;
  70.  
  71. }
  72.  
  73. str[j] = '\0';
  74. j = 0;
  75.  
  76. while(str[j] != '\0'){
  77.  
  78. if(str[j]=='_' || (str[j]>='A' && str[j] <= 'Z') || (str[j]>='a' && str[j] <= 'z')){
  79.  
  80. }
  81. else{
  82. error_flag=1;
  83. break;
  84. }
  85. j++;
  86. }
  87.  
  88. if(error_flag == 0){
  89. printf("%s\n",str);
  90. //fprintf(file,"%s",str);
  91. }
  92. else
  93. printf("Error!\n");
  94.  
  95.  
  96. }
  97. //fclose(file);
  98. return 0;
  99. }
  100.  
Success #stdin #stdout 0s 2012KB
stdin
long_and_mnemonic_identifier
anotherExample
i
bad_Style
aA
AAa
nEERC
stdout
longAndMnemonicIdentifier
another_example
i
Error!
a_a
Error!
n_e_e_r_c