(11-30-2014, 08:10 PM)Psycho_Coder Wrote: Did I clearly stated that I want you to make an intellisense for the challenge ?
Solve this : https://sinister.li/Thread-Contest-C...f-Grouping
A guy with about 7 yrs of experience would be able to solve this in 2-3 hrs and not more.
Go forward and reply when you have the solution. Choose any language you want to code in but you cannot use any external library (or else there isn't any point of a challenge)
I wont do it but..
Quote:3. Use of "==" and index(), find() and string slicing allowed, but functions like startswith() and endswith() are not allowed if inbuilt, if you create it with code then its fine.
Here you go, startswith(), endswith() in C++:
Code:
bool StartsWith(char* pszBuffer, char* pszData)
{
int iDataLen = strlen(pszData);
char* pszCheckData = (char*)malloc(iDataLen);
memcpy(pszCheckData, pszBuffer, iDataLen);
return lstrcmpA(pszCheckData, pszData) == 0;
}
bool EndsWith(char* pszBuffer, char* pszData)
{
int iBufferLen = strlen(pszBuffer);
int iDataLen = strlen(pszData);
char* pszCheckData = (char*)malloc(iDataLen);
memcpy(pszCheckData, pszBuffer + (iBufferLen - iDataLen), iDataLen);
return lstrcmpA(pszCheckData, pszData) == 0;
}
Wrote it in this editor, took 2 minutes. Maybe now u believe I can code? lol
Ok, here is even logic how they work:
StartsWith -
You take the number of bytes from your buffer your data to check length is. Then comare if those bytes match your data to check. If they do, then it starts with that shit.
EndsWith-
The same as StartsWith but you take those bytes from the end of the string, calculated by strlen(buffer) - strlen(data_to_check).