A new online coding contest

Hi guys,
I know there are quite a lot such contests already, but this one I found to be really cool and enjoyable. Since I am a newbie, I can only manage a couple of the contest puzzles. But they are all really programming puzzles, not math tests!

If you are good, you can even win an iPad! The site is called CoderCharts (http://codercharts.com).

One thing I like especially is their source code editor ... really well-thought and user-friendly. Nice looking too.

Go check it out and good luck!
Maybe I'll try this out.
I tried it, for some lame reason it keeps telling me that my output is incorrect for the Noob Cipher (I started out easy).

I tried this code (and about 8 variations to it):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
#include <algorithm>
#include <fstream>
#include <sstream>

using namespace std;

struct Cipher
{   string Clear;
    string Crypt;
    Cipher(string cr="ZYXWVUTSRQPONMLKJIHGFEDCBA", string cl="ABCDEFGHIJKLMNOPQRSTUVWXYZ") : Clear(cl), Crypt(cr) {}
    ~Cipher() {}};

const std::string Decrypt(const std::string& d, const Cipher& c)
{   std::string out;
    unsigned u(0);
    while(u<d.size())
    {   unsigned i(0);
        while(c.Crypt[i]!=d[u]&&i<c.Crypt.size()){i++;}
        if (c.Crypt[i]!=d[i]) out += c.Clear[i];
        else out += d[u];
        u++;}
    return out;}

inline void to_up(char& c){if(c>='a'&&c<='z') c+='A'-'a';}

int main(int argc, char* argv[])
{
    if (argc==3)
    {   fstream file(argv[2], fstream::in);
        if (file.is_open())
        {   Cipher c;
            string table = argv[1];
            string content;
            do
            {
                getline(file,content);
                for_each(table.begin(),table.end(),to_up);
                for_each(content.begin(),content.end(),to_up);
                c.Crypt = table;
                cout << Decrypt(content,c);
                if (!file.eof()) cout << '\n';
            } while(!file.eof());
        }
    }
    return 0;}
I tried it too. A bit.
@Kyon, had the same problem. Then changed fstream to ifstream and it worked.
Last edited on
My fastgrep doesn't work, even though I've tested it, and it does work. It passes "verify" but fails when I submit it.

http://codepad.org/jkunLGeW

$ ./fgrep "int main" fgrep.c
59
$ ./fgrep -ly "int main" fgrep.c
59
$ ./fgrep -cy "int main" fgrep.c
59:0
$ ./fgrep -fy -cy "int main" fgrep.c
fgrep.c:59:0
$ ./fgrep -fy -cy "int main" fgrep.c
fgrep.c:59:0
$ ./fgrep -fy -cy "int main" fgrep.c
fgrep.c:59:0
$ ./fgrep -fy -cy "Int main" fgrep.c
0
$ ./fgrep "404: Not Found" fgrep.c
0
Last edited on
I tried the first one, which is pretty trivial, but I've never written a program where main() accepts arguments.
Could someone give me a basic example?

Edit: I seem to have figured it out just by guessing, but an in depth explanation would still help.

Edit Again: @Kyon: The substitution table is one of the arguments. It won't always be "ZYXWVUT..."
Last edited on
When I try to verify for the Noob cipher I'm getting this:
ERROR(incorrect): Incorrect result
Your submission failed to give the exact answer on the verification test. Please verify your code.
For reference, you program generated these results:
WELCOME TO CODER CHARTS

Any ideas what could be wrong? I've checked for new line characters.

@chrisname and kyon: Why are you're codes so complicated? Mine is only 22 lines long (not including whitespace).

Edit: Okay, I got it. Apparently you're supposed to exit when you hit a newline character?

Edit number 2^64: Nevermind. It verified correctly but I still got the wrong answer.
Last edited on
I like the score by running time.
@Kyon: line 21if (c.Crypt[i]!=d[i]) out += c.Clear[i]; that condition makes no sense. (edit: And it is not out of bounds just because they are strings and there is an '\0' at the end)

I think that you could assume that the input is not corrupted.
Last edited on
My code is not complicated. It's just longer. ;) I also added some "checks" for if a character was lowercase instead of uppercase.(using to_up() and for_each) The rest is just writing to a file (which is checked for being open) and calling a function or two.

EDIT:
Ne, that isn't for corrupted output, that is for when the loop exits, since it can exit for a multitude of reasons. If it runs out of characters to check, you will have to add the same character to maintain validity. If it exited before going out of characters to check, you should add the character from the Clear string.
I do however admit that the if was a bit bloated.. Could just have done some > and >= with i.
Last edited on
I meant that those checks are unnecessary, (to_up)

If it runs out of characters to check, you will have to add the same character to maintain validity
You aren't checking that (line 21)
@hamsterman: So, did your submission pass? I can't figure out what's wrong with mine:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<fstream>

int main(int argc, char** argv)
{
    std::ifstream infile(argv[2]);
    char letter;
    char *table = argv[1];
    char nsub[26];
    for (int i = 0; i < 26; i++)
        nsub[table[i]-'A'] = i+'A';
    while (!infile.eof())
    {
        infile.get(letter);
	if (letter < 'A' || letter > 'Z')
	{
	    if (letter == '\n')
	    	break;
	    std::cout << letter;
	    continue;
	}
        std::cout << nsub[letter-'A'];
    }
    infile.close();
    return 0;
}

Edit: updated code. How's it now?
Last edited on
I was doing another one..
Does this code work when you test it yourself?
By the way, 88 is 'X'. You're ignoring Y and Z.
To prevent such errors I suggest using quoted char instead of it's ASCII value. Would make the code more readable.

Speaking of which, I one saw a code where '!' , '+' and '5' were used as some offset constants that have nothing to do with the symbols themselves. It took a while before I understood that this wasn't supposed to make sense...
Wow, I feel stupid now. Anyway, I've gotten 100 pts. for this one now. I think the score = 100-slowest test.
Topic archived. No new replies allowed.