1
I’m trying to solve the problem 2253 - Password Validator, URI, but is giving 10% wrong answer, but all my tests are working, someone can find the error?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int validade(char *S) {
int i, maiuscula = 0, minuscula = 0, numero = 0, tam = strlen(S) - 1;
if(tam < 6 || tam > 32)
return 0;
for(i = 0; i < tam; i++) {
if(isupper(S[i]))
maiuscula = 1;
else if(islower(S[i]))
minuscula = 1;
else if(isdigit(S[i]))
numero = 1;
else
return 0;
}
return maiuscula * minuscula * numero;
}
int main() {
char S[100];
while(fgets(S, 100, stdin) != NULL)
printf(validade(S) ? "Senha valida.\n" : "Senha invalida.\n");
return 0;
}
The problem requires the while because the entry of the dreaded problem with end of file, but thanks anyway.
– pcesarmf
But it makes no sense, because this function does not return a file end but a pointer.
– Maniero
@Lettuce, you can ask her yourself
stdin
if she’s already finished:feof(stdin)
– Jefferson Quesado
Or check in the documentation that he returns
NULL
when it reaches the end of the file and cannot read even 1 character– Jefferson Quesado
I switched to NULL and now does not exceed the time limit, but there is 10% wrong answer :/
– pcesarmf
There’s no point in asking
EOF
right in thefgets
withstdin
. When he switched toNULL
essentially made thewhile
not be necessary more, then do the same as my answer, only mine has no unnecessary instructions. The goal of these exercises is to make learn and not be able to solve them and not understand what is there.– Maniero
I understand what’s there, but it’s that I really need to figure out how it’s there, it’s a practical job.
– pcesarmf
Well, only you know what’s there, and if that’s what you’re talking about, it asks you to do something wrong, or you’re interpreting something wrong. It is difficult to help more than this given what was past. The question did not speak of this, so what was asked has already been answered.
– Maniero
Lettuce, it would be easier to explain if you had placed a link ;-) Maniero, the lettuce wants to answer this test:https://www.urionlinejudge.com.br/judge/pt/problems/view/2253. Its code will be validated by a file containing several lines, so the while'.
– mari
Thank you all, I solved the issue, I just switched from C to C++ and it worked.
– pcesarmf