Pārlūkot izejas kodu

New problem done

master
Lachlan Jacob pirms 5 gadiem
vecāks
revīzija
f07c636b11
3 mainītis faili ar 45 papildinājumiem un 0 dzēšanām
  1. 21
    0
      461/main.c
  2. 19
    0
      461/problem.txt
  3. 5
    0
      461/run.sh

+ 21
- 0
461/main.c Parādīt failu

@@ -0,0 +1,21 @@
#include <stdio.h>

int countBits(int);

int hammingDistance(int x, int y) {
return countBits(x ^ y);
}

int countBits(int v) {
int c;
for (c = 0; v; v >>= 1) {
c += v & 1;
}
return c;
}

int main() {
printf("Expected: 2\n");
printf("Got: %d\n", hammingDistance(1, 4));
return 0;
}

+ 19
- 0
461/problem.txt Parādīt failu

@@ -0,0 +1,19 @@
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note:
0 ≤ x, y < 231.

Example:

Input: x = 1, y = 4

Output: 2

Explanation:
1 (0 0 0 1)
4 (0 1 0 0)
↑ ↑

The above arrows point to positions where the corresponding bits are different.

+ 5
- 0
461/run.sh Parādīt failu

@@ -0,0 +1,5 @@
#!/bin/bash

gcc -o main main.c
./main
rm main

Notiek ielāde…
Atcelt
Saglabāt