Page 1 of 2

1825 - Creating Passwords I

Posted: Thu May 10, 2012 10:17 pm
by ymondelo20

Re: 1825 - Creating Passwords I

Posted: Fri Jan 23, 2015 12:20 pm
by karkazz
Hi, could someone direct me in the right direction, I don't know what I am missing with this problem...
The description states that
The name of any user is typically a set of words.
So I am considering that there could be empty names.
All words are separated by a single space.
But it doesn't say that there could be trailing or leading spaces, I got that in code too... And I assume there won't be more than 1 space between words.
All words have no more than 20 letters.
Ok, so a single word is not longer than 20 letters... but it doesn't state the maximum words there could be... I'm considering up to 102 words, are they not enough?
All words have only capital letters.
So I'm assuming that if leading or trailing spaces, all of them should be omitted, since ' ' is not a capital letter, then, not a word.

I've run a test, (When previewing the post, leading and trailing spaces where deleted so, I replaced them with [#spaces] instead):

342343 LUIS
435984 [9spaces]CARLOSD FGFG[6spaces]
234348 [1space]
633735 [1space]OLGALIDIA BROK SABALA JHSD DJBDF[2spaces]
435984 [8spaces]CARLOSD FGFG
435945 DLK
435950 [5spaces]

And I get this result

I added comments to the code to make it easier to read, but I sent it to the judge without comments

Removed code

So, what else am I missing :?:
Thanks for your time. :)

Re: 1825 - Creating Passwords I

Posted: Fri Jan 23, 2015 1:21 pm
by humbertodiaz
Would you mind posting your code for a moment? I think that I know what's wrong, but before I go off on a technical explanation of a obscure issue with COJ, it would be easier to confirm that your code doesn't have a simpler flaw. You can always post it and then edit your post to remove the code once the issue is found.

Re: 1825 - Creating Passwords I

Posted: Mon Jan 26, 2015 9:09 pm
by karkazz
Hi Humberto, I have added the code to my post.

Thank you very much for your time and advice.

Re: 1825 - Creating Passwords I

Posted: Mon Jan 26, 2015 9:34 pm
by humbertodiaz
First, a minor note: You don't need to use that special condition for line breaks. Just print '\n' after each case and you're good. Wow, that was some fancy use of printf and scanf.

Oh, before I forget - I don't believe an empty name would be legal.

So it seems that the issue here is a minor bug that affects some solutions on COJ. It'll be fixed in the future and then submissions will be rejudged, so in the long term, your WAs should become ACs.

Different operating systems have different ways of marking the end of a line. In Linux, the end of a line is simply "\n". In Windows, it's both of them in a specific sequence, "\r\n". The people who write exercises and their test cases work with various operating systems. Certainly, many of them use Windows. So some of the files for test cases have lines ending in "\r\n". COJ's engine used to convert those into "\n" automatically to avoid problems, but that broke during the recent changes. That filter applies to the outputs of our programs, too, and Jasr told me that's still working.

I'm certain that some test cases for this exercise have lines ending in Windows style. Your program copies "\r" into its output since you read the whole line until the line break. COJ then assumes that you wanted to create a new line and turns that character into a "\n". The result is that your output gets broken up incorrectly, like so:


Alternatively, if it's not converted, then it's just a weird character in your output. I'll simulate that with a dollar sign here:


You get the point. In your case, you should detect "\r" and turn it into a null terminator. You could also filter it from your reading, but that might complicate things, especially since we can't be sure that all test cases have that rogue character.

Re: 1825 - Creating Passwords I

Posted: Wed Jan 28, 2015 1:51 am
by karkazz
Oh the condition on the newline was only to avoid getting a Presentation Error, I pretty much use that in every several cases programs but I'll try it as you mention. About the empty name I thought of it as improbable too, but I just wanted to reduce the possibilities and try to find the "tricky" case that was making my code to get "wrong answer". I'll wait to see if my code gets "Right Answer" when they fix this bug and hope is not something else ;) .

Thank you very much for your time and knowledge :D.

Re: 1825 - Creating Passwords I

Posted: Wed Jan 28, 2015 6:24 am
by humbertodiaz
It might be a while before they do, unfortunately. I don't know the state of things lately - it's all been rather opaque - but it might be easier to work around the issue and try one more time.

Re: 1825 - Creating Passwords I

Posted: Tue Apr 21, 2015 3:45 am
by Jose132
I'm trying this problem but I sent it in C# and I got TLE and in C++ I have some problems with the getline, anybody knows how I can read a line with other code than getline or how I can read "good" a line with getline?, 'cose the getline count me the previous lines. :?

Estoy intentando este problema pero lo mandé en C# y obtuve TLE y en C++ tengo problemas con el getline, ¿alguien sabe cómo puedo leer una linea con otro código que no sea el getline o cómo puedo leer "bien" con el getline?, porque el getline me cuenta también las lineas previas. :?

Re: 1825 - Creating Passwords I

Posted: Tue Apr 21, 2015 9:36 am
by humbertodiaz
No creo que getline() te da lineas anteriores. Yo explique aqui lo que pasa con COJ que probablemente esta causando tus problemas. Las recomendaciones que escribi deben resolver la situacion.

Re: 1825 - Creating Passwords I

Posted: Tue Apr 21, 2015 11:00 am
by ymondelo20
Yo utilizo algo como esto:

Code: Select all

... lee a lo sumo 550 caracteres, y se detiene si encuentra el fin de línea. L, es un arreglo de caracteres.
Lo único notable es que se debe realizar una lectura extra, antes de comenzar a leer las líneas del problema (la cual toma el fin línea que sigue al número de casos).

Igual se puede trabajar con la función gets()...