1825 - Creating Passwords I

Discussion around the problems of the COJ.
Forum rules
Remember that posting AC code is not allowed here. If you are going to ask a question or to post a solution, describe your algorithm instead. Posting AC code will be penalized.
User avatar
ymondelo20
Posts: 1968
Joined: 8 years ago
Location: Universidad de las Ciencias Informáticas
Gender: None specified
Contact:

1825 - Creating Passwords I

Post by ymondelo20 » 7 years ago



"Every problem has a simple, fast and wrong solution" OJ's Main Law. ;)

karkazz
Posts: 4
Joined: 4 years ago
Gender: None specified

Re: 1825 - Creating Passwords I

Post by karkazz » 4 years ago

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):

13
123233
346653 RITA GARCIA HERNANDEZ
342343 LUIS
435984 [9spaces]CARLOSD FGFG[6spaces]
463756 MANUEL GONZALEZ BRITO
234348 [1space]
633735 [1space]OLGALIDIA BROK SABALA
349834 WEROIWER WERJUWE RJER WEROIUWER WEORIWERW WERJIWE RJIWE[1space]
459834 RGIJ DFKJF
633735 [1space]OLGALIDIA BROK SABALA JHSD DJBDF[2spaces]
435984 [8spaces]CARLOSD FGFG
435945 DLK
435950 [5spaces]


And I get this result
123233
346RITA*GARCIA*HERNANDEZ653
342LUIS343
435CARLOSD*FGFG984
463MANUEL*GONZALEZ*BRITO756
234348
633OLGALIDIA*BROK*SABALA735
349WEROIWER*WERJUWE*RJER*WEROIUWER*WEORIWERW*WERJIWE*RJIWE834
459RGIJ*DFKJF834
633OLGALIDIA*BROK*SABALA*JHSD*DJBDF735
435CARLOSD*FGFG984
435DLK945
435950

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

---EDIT2---
Removed code

So, what else am I missing :?:
Thanks for your time. :)
Last edited by karkazz on Wed Jan 28, 2015 1:42 am, edited 2 times in total.

humbertodiaz
Posts: 97
Joined: 5 years ago
Gender: None specified

Re: 1825 - Creating Passwords I

Post by humbertodiaz » 4 years ago

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.

karkazz
Posts: 4
Joined: 4 years ago
Gender: None specified

Re: 1825 - Creating Passwords I

Post by karkazz » 4 years ago

Hi Humberto, I have added the code to my post.

Thank you very much for your time and advice.
Greetings!

humbertodiaz
Posts: 97
Joined: 5 years ago
Gender: None specified

Re: 1825 - Creating Passwords I

Post by humbertodiaz » 4 years ago

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:

346RITA*GARCIA*HERNANDEZ
653

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:

346RITA*GARCIA*HERNANDEZ$653

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.

karkazz
Posts: 4
Joined: 4 years ago
Gender: None specified

Re: 1825 - Creating Passwords I

Post by karkazz » 4 years ago

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.

humbertodiaz
Posts: 97
Joined: 5 years ago
Gender: None specified

Re: 1825 - Creating Passwords I

Post by humbertodiaz » 4 years ago

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.

User avatar
Jose132
Posts: 47
Joined: 4 years ago
Location: Matanzas - Cuba
Gender: None specified
Contact:

Re: 1825 - Creating Passwords I

Post by Jose132 » 4 years ago

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. :?
:-) "Behind every code is an enigma" :-)

humbertodiaz
Posts: 97
Joined: 5 years ago
Gender: None specified

Re: 1825 - Creating Passwords I

Post by humbertodiaz » 4 years ago

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.

User avatar
ymondelo20
Posts: 1968
Joined: 8 years ago
Location: Universidad de las Ciencias Informáticas
Gender: None specified
Contact:

Re: 1825 - Creating Passwords I

Post by ymondelo20 » 4 years ago

Yo utilizo algo como esto:

Code: Select all

cin.getline(L,550,'\n');
... 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()...
"Every problem has a simple, fast and wrong solution" OJ's Main Law. ;)

Post Reply

Return to “Problem set”