### NeekT's blog

By NeekT, history, 2 months ago,

I was attempting problem 118A (https://codeforces.com/problemset/problem/118/A) and I got it wrong the first time. I'd like some help to figure out what went awry (my submission: https://codeforces.com/contest/118/submission/107014817) but my major issue is another one. I was looking at some other solutions to get clues about my own mistakes, and I found this submission as an accepted answer:

#include<stdio.h>
#include<string.h>
main()
{
char a[101];int i;
gets(a);
strlwr(a);
for(i=0;a[i]!='\0';i++)
{if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'||a[i]=='y')
;else
printf(".%c",a[i]);}
}


The instructions for the problem are quite clear: "The program's input is exactly one string, it should return the output as a single string," but in this solution the answer is not a single string. A single string should be printed out with something like "%s",string. What am I missing here?

• -27

By NeekT, history, 3 months ago,

Hi everyone, i'm trying to solve problem 4C. (https://codeforces.com/problemset/problem/4/C)

You have to build a database of usernames and modify the entry if the name is already taken. I defined a data structure to hold the username and the number of time it appears in the database. Then i asked for each username and checked for repetitions. This is my first attempt:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_NAME 32

typedef struct{
int rep;
char name[MAX_NAME+1];
}entry_t;

int main(){
entry_t* db;
int i,j,n;

scanf("%d", &n);
db=malloc(sizeof(entry_t)*n);/*Allocate memory for the name database*/
if(db){

for(i=0; i<n; i++)  /*Set all repetions of each entry to zero*/
db[i].rep=0;

for(i=0; i<n; i++){  /*Acquire entry and check for repetitions*/
scanf("%s", db[i].name);
for(j=0; j<i; j++){
if(!strcmp(db[i].name, db[j].name))
(db[i].rep)++;
}                   /*Print out the results*/
if(!(db[i].rep))
printf("OK\n");
else
printf("%s%d\n", db[i].name, db[i].rep);
}
}else
printf("Errore allocazione memoria");
return 0;
}


I tried to allocate the memory using the malloc function and i got the Time Limit Exceeded error code. So i tried (mostly out of desperation) to declare a big enough array to hold all the data, this way:

typedef struct{
int rep;
char name[MAX_NAME+1];
}entry_t;

int main(){
entry_t db[10000];



and i got a different error: Runtime Error. So i tried to go bigger

typedef struct{
int rep;
char name[MAX_NAME+1];
}entry_t;

int main(){
entry_t db[100000];
int i,j,n;


and i got again the Time Limit Exceed error.

Can someone give me a hint about what i'm doing wrong? Also, i'd rather not use "continue" or "break" commands since my professor doesn't want me to get in the habit of it...go figure. I've seen some accepted answers that seem to be very similar to mine except for these two commands. I've also seen some people using a hashing function, which seems a really cool thing to learn but I'd like to go for a more basic approach first. Thanks.

• -17

By NeekT, history, 3 months ago,

Hello everybody.

If i try the input for test 7 (the number 4744000695826) on my machine i get the right output (YES) but when i submit the code, the test on the same output gives the wrong answer (NO).

Here's my submission for the problem in the title (GNU C11)

#include "stdio.h"

int main(){
int i,c;
long long int n;
scanf("%lld",&n);

for(c=0; n>0; n/=10){
if((n%10 == 4)||(n%10==7))
c++;
}

if((c==4)||(c==7))
printf("YES");
else
printf("NO");
return 0;
}


I tried to mess around with the % operator but if i use %ld i get the same exact outcome (the problem is solved correctly on my machine but the test run by the online judge gives a different answer), so i tried with %d and at the very least i got some consistency: both my machine and the online judge spit out a clear NO.

Could someone help me figure out what's wrong here?

Here's the link to my latest submission in case you want to check out the full test details https://codeforces.com/problemset/submission/110/105489826

Here's a screenshot for the test on my machine