codedprobyte Posted May 6, 2013 at 10:26 PM Report #505988 Posted May 6, 2013 at 10:26 PM (edited) Boas pessoal, é o seguinte: Estou a desenvolver uma Cache em C, que tem de ser configurável. A questão é que o programa está todo implementado e em relação aos outputs que deve gerar, estão todos a corresponder. Porém ao submeter a um site de submissão de programas como é o caso do mooshak, este dá Wrong answer. Alguém pode dar uma vista de olhos por algumas partes e perceber do que se possa vir a tratar? Cumprimentos Edited May 10, 2013 at 12:54 PM by brunoais titulo melhorado
HappyHippyHippo Posted May 6, 2013 at 10:34 PM Report #505990 Posted May 6, 2013 at 10:34 PM não está a faltar nada no teu post ? tipo o código ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
codedprobyte Posted May 6, 2013 at 10:37 PM Author Report #505991 Posted May 6, 2013 at 10:37 PM (edited) int main(int argc, char *argv[]){ char adress[MAX_SIZE]; char *s=adress; char *w; int** matrix; int* fifoValues; int row, column, k; int index, nway, capacity, bloco, tagSize; int valido, tag, b, fifo, posfifo, hit, filled, linhas, linhas2, contador, x, y; int adressSize, offsetSize, indexSize; fifo=0; index=0; nway=0; capacity=0; bloco=0; tagSize=0; adressSize=DEFAULT_ADRESS_SIZE; offsetSize=DEFAULT_OFFSET; indexSize=DEFAULT_INDEX; bloco=DEFAULT_BLOCO; capacity=DEFAULT_CAPACITY; nway= DEFAULT_WAYS; while(index<argc){ if(*argv[index]=='W'){ nway=atoi(argv[++index]); }else if(*argv[index]=='S'){ capacity=atoi(argv[++index]); }else if(*argv[index]=='B'){ bloco=atoi(argv[++index]); offsetSize= getOffset(bloco); }else if(*argv[index]=='E'){ adressSize=atoi(argv[++index]); } index++; } row=getRows(capacity, bloco, nway); column=(nway*THREE); indexSize=getOffset(row); tagSize=(adressSize-(offsetSize+indexSize)); matrix=(int**)malloc(row*sizeof(int*)); for(linhas=0; linhas<row; linhas++){ matrix[linhas]=(int*)malloc(column*sizeof(int)); } fifoValues=malloc(row*sizeof(int)); while(s!=NULL){ s=fgets(adress, MAX_SIZE, stdin); if(s==NULL){ return 0; } b=positionDefault(s, adressSize, offsetSize, indexSize); w=malloc(tagSize*sizeof(int)); strncpy(w, s, tagSize); k=toInt(w); free(w); valido=0; tag=2; posfifo=1; hit=0; filled=0; while(valido*3 < column && filled==0){ if((matrix[b][valido*3])==0){ matrix[b][valido*3]=1; matrix[b][tag]=k; (fifoValues[b])++; //fifo++; matrix[b][posfifo]=(fifoValues[b]); //fifo; filled=1; }else if(matrix[b][tag]==k){ hit=1; filled=1; } valido++; tag=tag+3; posfifo=posfifo+3; } posfifo=1; contador=4; y=posfifo; x=matrix[b][posfifo]; if(filled==0){ while(contador < column){ if(x > matrix[b][posfifo+3]){ x=matrix[b][posfifo+3]; y=posfifo+3; filled=1; } contador+=3; posfifo+=3; } if(matrix[b][y+1]!=k){ matrix[b][y+1]=k; (fifoValues[b])++; matrix[b][y]=(fifoValues[b]); } else hit=1; } if(hit==0) printf("%c\n",'M'); else printf("%c\n",'H'); } for(linhas=0; linhas<row; linhas++){ free(matrix[linhas]); } free(matrix); return 0; } Edited May 6, 2013 at 10:48 PM by thoga31 tags CODE + GeSHi
HappyHippyHippo Posted May 7, 2013 at 09:10 AM Report #506016 Posted May 7, 2013 at 09:10 AM se eu meter isso num ficheiro e enviar para um cmopilar, isso compila ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
codedprobyte Posted May 7, 2013 at 04:23 PM Author Report #506129 Posted May 7, 2013 at 04:23 PM Já está resolvido, obrigado pessoal, podem eliminar se possível. Boa programação!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now