confused.....need more samples of input and output....
i got it right on my computer but received "wrong answer" from online judge??...........what's cryptal?? what's wrong??
#include<stdio.h>
#include<ctype.h>
char line[100];
int f[26],j;
int main(){
unsigned int max,baris,i;
char huruf[26];
Using fflush is wrong. fflush is only used for ensuring that all data written to a stream is really written to disk (or at least to kernel buffers...). You cannot use fflush to consume the newline character after the number on the first line. Instead, you could simply do
[c]gets(line);[/c] right after scanf.
Other things you might want to watch out for is lines longer than 100 characters. I don't know how long the lines are in the judge input but there is no limit mentioned in the specification as far as I can see.
For the TLE: you should only change the value of the max when you came upon a character, which is a letter... like this:
Hisoka wrote:I dont know Why I got TLE if I use this program in c:
[c]
for(j=0;kalimat[j];j++)
{
if(isalpha(kalimat[j])) {
banyak[toupper(kalimat[j])-'A']++;
if(banyak[toupper(kalimat[j])-'A']>max)
max=banyak[toupper(kalimat[j])-'A'];
}
}
[/c]
Dealing with failure is easy: Work hard to improve.
Success is also easy to handle: You've solved the wrong problem. Work hard to improve.
Hello, ... your 2nd program might be accessing an invalid index. That might be why it got WA.
Try to trace with k = 1. The first if statement below will be comparing angka[-1] and angka[0]. And then it depends what is currently stored in angka[-1] ... you might end up swapping your huruf and angka because it is less than angka[0].
I haven't tried your program, but you shouldn't use fflush(). It is not meant for consuming the newline character, but rather flushing output buffers to assure that they are written to kernel buffers. One way you could do it is:
[c]gets(temp);[/c]
or by looping:
[c]while (getchar() != '\n') ;[/c]
By replacing fflush(stdin); with one of the above examples your program is likely to work.