posts - 5,  comments - 0,  trackbacks - 0
  2007年3月16日
关于公历闰年是这样规定的:地球绕太阳公转一周叫做一回归年,一回归年长365日5时48分46秒。因此,公历规定有平年和闰年,平年一年有365日,比回归年短0.2422日,四年共短0.9688日,故每四年增加一日,这一年有366日,就是闰年。但四年增加一日比四个回归年又多0.0312日,400年后将多3.12日,故在400年中少设3个闰年,也就是在400年中只设97个闰年,这样公历年的平均长度与回归年就相近似了。由此规定:年份是整百数的必须是400的倍数才是闰年,例如1900年、2100年就不是闰年。
posted @ 2007-03-16 16:55 forever 阅读(143) | 评论 (0)编辑 收藏
  2007年3月15日
七种qsort排序方法
[ 2007-1-12 9:41:00 | By: Hailer ]
 
七种qsort排序方法

<本文中排序都是采用的从小到大排序>

一、对int类型数组排序

int num[100];

Sample:

int cmp ( const void *a , const void *b)
{
return *(int *)a - *(int *)b;
}

qsort(num,100,sizeof(num[0]),cmp);

二、对char类型数组排序(同int类型)

char word[100];

Sample:

int cmp( const void *a , const void *b)
{
return *(char *)a - *(char *)b;
}

qsort(word,100,sizeof(word[0]),cmp);

三、对double类型数组排序(特别要注意)

double in[100];

int cmp( const void *a , const void *b)
{
return *(double *)a > *(double *)b ? 1 : -1;
}

qsort(in,100,sizeof(in[0]),cmp);

四、对结构体一级排序

struct In
{
double data;
int other;
}s[100]

//按照data的值从小到大将结构体排序,关于结构体内的排序关键数据data的类型可以很多种,参考上面的例子写

int cmp( const void *a ,const void *b)
{
return (*(In *)a).data > (*(In *)b).data ? 1 : -1;
}

qsort(s,100,sizeof(s[0]),cmp);

五、对结构体二级排序

struct In
{
int x;
int y;
}s[100];

//按照x从小到大排序,当x相等时按照y从大到小排序

int cmp( const void *a , const void *b)
{
struct In *c = (In *)a;
struct In *d = (In *)b;
if(c->x != d->x) return c->x - d->x;
else return d->y - c->y;
}

qsort(s,100,sizeof(s[0]),cmp);

六、对字符串进行排序

struct In
{
int data;
char str[100];
}s[100];

//按照结构体中字符串str的字典顺序排序

int cmp ( const void *a , const void *b)
{
return strcmp( (*(In *)a).str , (*(In *)b).str);
}

qsort(s,100,sizeof(s[0]),cmp);

七、计算几何中求凸包的cmp

int cmp(const void *a,const void *b) //重点cmp函数,把除了1点外的所有点,旋转角度排序
{
struct point *c=(point *)a;
struct point *d=(point *)b;
if( calc(*c,*d,p[1]) < 0) return 1;
else if( !calc(*c,*d,p[1]) && dis(c->x,c->y,p[1].x,p[1].y) < dis(d->x,d->y,p[1].x,p[1].y)) //如果在一条直线上,则把远的放在前面
return 1;
else return -1;
}

PS:

其中的qsort函数包含在<stdlib.h>的头文件里,strcmp包含在<string.h>的头文件里
posted @ 2007-03-15 13:43 forever 阅读(169) | 评论 (0)编辑 收藏
  2007年3月14日
http://tcno.net/doc/tor/
简单点就是:
1、下载Firefox和Vidalia套件(http://www.vidalia-project.net/download.php
2、安装软件
3、为Firefox安装插件FoxTor

posted @ 2007-03-14 20:33 forever 阅读(194) | 评论 (0)编辑 收藏

Faulty Odometer


Time Limit : 1 second    Memory Limit : 32768 KB
Total Submit : 249    Accepted Submit : 141

Problem

You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 3 to the digit 5, always skipping over the digit 4. This defect shows up in all positions (the one's, the ten's, the hundred's, etc.). For example, if the odometer displays 15339 and the car travels one mile, odometer reading changes to 15350 (instead of 15340).

Input

Each line of input contains a positive integer in the range 1..999999999 which represents an odometer reading. (Leading zeros will not appear in the input.) The end of input is indicated by a line containing a single 0. You may assume that no odometer reading will contain the digit 4.

Output

Each line of input will produce exactly one line of output, which will contain: the odometer reading from the input, a colon, one blank space, and the actual number of miles traveled by the car.

Sample input

13
15
2003
2005
239
250
1399
1500
999999
0

Sample output

13: 12
15: 13
2003: 1461
2005: 1462
239: 197
250: 198
1399: 1052
1500: 1053
999999: 531440

#include<cstdio>

#include<string>

#include<cmath>

using namespace std;

int main()

{

       char a[11], temp[11];

       int n, sum;

       int i, j, k;

       while(scanf("%s", a)!=EOF) {

              sum=0;

              n=strlen(a);

              if(n==1 && a[0]=='0') break;

              for(i=0; i<n; i++) {

                     temp[i]=a[i]-48;

                     //if(temp[i]>4) temp[i]--;                    

              }    

              for(i=0; i<n-1; i++) {

                     if(temp[i]<4)   sum=sum+temp[i]*(int)pow(double(9), double(n-i-1));

                     else sum=sum+(temp[i]-1)*(int)pow(double(9), double(n-i-1));

              }

              if(temp[n-1]>4) sum=sum+temp[n-1]-1;

              else sum=sum+temp[n-1];

                    

             

              printf("%s: %d\n", a, sum);

       }

       return 0;

}

posted @ 2007-03-14 15:04 forever 阅读(328) | 评论 (1)编辑 收藏
     摘要: ASCII 值 ...  阅读全文
posted @ 2007-03-14 13:16 forever 阅读(204) | 评论 (0)编辑 收藏
仅列出标题