Hi;
I'm doing the problem JAVAC (spoj.pl/problems/JAVAC/) and I wrote a code that compiles and works fine, on my computer, but when I submit it, I got a CE;
I have read the code a lot, and I still can't find the error; Could you help me?
PS: If you need me to traslate the ids name in order to make the code easier to read, please tell me
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
string Cpp(char* entrada, int indice, string nuevo)
{
bool Mayus = false;
while (indice < strlen(entrada)){
if (Mayus && (int)entrada[indice] >= 97 && (int)entrada[indice] <= 122)
{
nuevo += char((int)entrada[indice] - 32);
Mayus = false;
} else if (entrada[indice] == '_' && !Mayus)
{
Mayus = true;
} else if ((int)entrada[indice] >= 97 && (int)entrada[indice] <= 122 && !Mayus)
{
nuevo += entrada[indice];
} else
{
return "Error!";
}
indice++;
}
if (Mayus)
{
return "Error!";
}
return nuevo;
}
string Java(char* entrada, int indice, string nuevo)
{
while (indice < strlen(entrada))
{
if ((int)entrada[indice] >= 62 && (int)entrada[indice] <= 90)
{
nuevo += '_';
nuevo += char((int)entrada[indice] + 32);
}
else if ((int)entrada[indice] >= 97 && (int)entrada[indice] <= 122)
{
nuevo += entrada[indice];
} else {
return "Error!";
}
indice++;
}
return nuevo;
}
string iniciar_id(char* entrada)
{
int indice = 0;
bool fin = false;
string nuevo = "";
if (!((int)entrada[indice] >= 97 && (int)entrada[indice] <= 122))
{
return "Error!";
}
while (!fin)
{
if ((int)entrada[indice] >= 97 && (int)entrada[indice] <= 122)
{
nuevo += entrada[indice];
} else if (entrada[indice] == '_')
{
return Cpp(entrada, indice, nuevo);
} else {
return Java(entrada, indice, nuevo);
}
indice++;
if (indice >= strlen(entrada))
{
fin = true;
}
}
return nuevo;
}
int main()
{
while(!cin.eof())
{
char* entrada = new char[255];
cin >> entrada;
cout << iniciar_id(entrada).c_str() << endl;
}
return 0;
}