fork download
  1. #include <iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. int main() {
  6. string str;
  7. while(getline(cin,str))
  8. {
  9. int a=0,b=0,count=0;
  10. if(str[0]=='_'||(str[0]>='0'&&str[0]<='Z')||str[str.size()-1]=='_')
  11. {
  12. count++;
  13. cout<<"Error!"<<endl;
  14. }
  15. for(int i=0;i<str.size()&&count==0;i++)
  16. {
  17. if(str[i]=='_')
  18. {
  19. a++;
  20. i++;
  21. if(str[i]=='_')
  22. {
  23. count++;
  24. cout<<"Error!"<<endl;
  25. break;
  26. }
  27. else i--;
  28. }
  29. else if(str[i]>'A'&&str[i]<='Z')
  30. {
  31. b++;
  32. }
  33. else if(str[i]>='0'&&str[i]<='9')
  34. {
  35. cout<<"Error!"<<endl;
  36. count++;
  37. break;
  38. }
  39. else if(str[i]<=47||(str[i]>=91&&str[i]<=96)||str[i]>=123)
  40. {
  41. cout<<"Error!"<<endl;
  42. count++;
  43. break;
  44. }
  45. }
  46. if(a>=0&&b==0&&count==0)
  47. {
  48. for(int i=0;i<str.size();i++)
  49. {
  50. if(str[i]=='_')
  51. {
  52. i++;
  53. str[i]-=32;
  54. cout<<str[i];
  55. }
  56. else
  57. cout<<str[i];
  58. }cout<<endl;
  59. }
  60. else if(a==0&&b>0&&count==0)
  61. {
  62. for(int i=0;i<str.size();i++)
  63. {
  64. if(str[i]>='A'&&str[i]<='Z')
  65. {
  66. cout<<"_";
  67. str[i]+=32;
  68. cout<<str[i];
  69. }
  70. else
  71. {
  72. cout<<str[i];
  73. }
  74. }cout<<endl;
  75. }
  76. else if(a>0&&b>0)
  77. cout<<"Error!"<<endl;
  78. //}
  79. }
  80. // your code here
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0s 15240KB
stdin
A
string_convert2_integer
_
a_
foo__foo
foo_barBaz
#$long_and_mnemonic_identifier
anotherExample
i
1
bad_Style
l1ongt
r#h
stdout
Error!
Error!
Error!
Error!
Error!
Error!
Error!
another_example
i
Error!
Error!
Error!
Error!