UVA Solution 484 - The Department of Redundancy Department - Code in C/cpp - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Monday, May 22, 2017

UVA Solution 484 - The Department of Redundancy Department - Code in C/cpp

UVA Solution  484 - The Department of Redundancy Department - Volume 4


UVA Online Judge Solution  484 - The Department of Redundancy Department | Volume 4
UVA Problem Link -  484 - The Department of Redundancy Department

Problem Name:  484 - The Department of Redundancy Department
Problem Number : UVA -  484 - The Department of Redundancy Department
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : C, C plus plus

UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list

UVA Solution  484 - The Department of Redundancy Department Code in C/CPP:

#include<stdio.h>
#include<string.h>
#define Mod 100000
#define MaxL 1000000
int HASH[Mod], size;
typedef struct {
 int v, time, next;
}C;
C Node[MaxL];
int insHash(int v) {
 int m = ((v%Mod)+Mod)%Mod;
 int now = HASH[m], pre = 0;
 while(now) {
  if(Node[now].v < v)
   pre = now, now = Node[now].next;
  else if(Node[now].v == v) {
   Node[now].time++;return 1;
  } else {
   break;
  }
 }
 size++;
 if(!pre) HASH[m] = size;
 else  Node[pre].next = size;
 Node[size].v = v, Node[size].time = 1;
 Node[size].next = now;
 return 0;
}
int main() {
 int n, i;
 memset(HASH, 0, sizeof(HASH));
 size = 0;
 while(scanf("%d", &n) == 1)
  insHash(n);
 for(i = 1; i <= size; i++)
  printf("%d %d\n", Node[i].v, Node[i].time);
    return 0;
}


Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list, UVA 484 code in C, UVA  484 - The Department of Redundancy Department   code in C++, UVA solution in C, UVA the department solution

No comments:

Post a Comment