■掲示板に戻る■ 全部 1- 最新50

名無しさん@UNIX板 討議用スレ Part2

40 :これで勝負だ :2001/08/19(日) 17:45
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

typedef struct {
 long votes;
 const char *name;
} anontype;

static anontype anons[] = {
  {0, "名無しさん@コート脱いだらハワイのミポリソ萌え"},
  {0, "私の名前は名無しです。"},
  {0, "su nobody"},
  {0, "/home/名無しさん"},
  {0, "名無sh"},
  {0, "名無しさん@こあだんぷ"},
  {0, "名無しさん@お腹いっぱい。(現状維持)"},
  {0, "名無しSun"},
  {0, "名無しさん@Permission denied"},
  {0, "臆病者の名無しさん"},
  {0, "厨房@Permission denied"},
  {0, "Anonymous Coward"}};

#define arraylen(a) (sizeof a/sizeof *a)

int
cmpfn(const void *s1, const void *s2) {
 return ((const anontype *)s2)->votes-((const anontype *)s1)->votes;
}

int
main(int argc, char *const *argv)
{
 int i, j, r_scale, v_scale;
 long v_max = 0;
 long long v_total = 0;
 srand48((long)(time(NULL)^getpid()));
 for (i = 0; i < arraylen(anons); i++) {
  v_total += anons[i].votes = lrand48();
  if (v_max < anons[i].votes) v_max = anons[i].votes;
 }
 r_scale = (int)log10(arraylen(anons))+1;
 v_scale = (int)log10(v_max)+1;
 qsort(anons, arraylen(anons), sizeof *anons, cmpfn);
 printf("投票総数 %llu票\n", v_total);
 for (i = 0; i < arraylen(anons); i++)
  printf("%.*u位 %.*lu票 %s\n", r_scale,
    !i||anons[i-1].votes>anons[i].votes?(j=i+1):j,
    v_scale, anons[i].votes, anons[i].name);
 return 0;
}


新着レスの表示

掲示板に戻る 全部 前100 次100 最新50
名前: E-mail (省略可) :

read.cgi ver5.26+ (01/10/21-)