sopherwenxin学习笔记

刀锋上的舞者: 我是风中的落叶,看我如何飞翔
posts - 5, comments - 8, trackbacks - 0, articles - 1

2006年2月19日

方法1 
#include <stdio.h>
void main()
{
        int i=80;
        int j=10;
        i=i+j;
        j=i-j;
        i=i-j;
        printf("i=%d\n",i);
        printf("j=%d\n",j);
}
方法2
#include <stdio.h>
void main()
{
        int i=80;
        int j=10;
        i^=j;
        j^=i;
        i^=j;
  printf("i=%d\n",i);
        printf("j=%d\n",j);
}
方法3
#include <stdio.h>
void main()
{
        int i=80;
        int j=10;
        i=i+j-(j=i);
        j=j+i-(i=j);
  printf("i=%d\n",i);
        printf("j=%d\n",j);
}






posted @ 2006-02-19 15:46 sopherwenxin 阅读(438) | 评论 (1)编辑 收藏

2006年1月15日

关于scanf的返回值,MSDN里是这样写的:
Both scanf and wscanf return the number of fields successfully converted
and assigned; the return value does not include fields that were read but
not assigned. A return value of 0 indicates that no fields were assigned.
The return value is EOF for an error or if the end-of-file character or the
end-of-string character is nocountered in the first attempt to read a character.
如:
scanf("%d%d", &a, &b);
如果a和b都被成功读入,那么scanf的返回值就是2
如果只有a被成功读入,返回值为1
如果a和b都未被成功读入,返回值为0
如果遇到错误或遇到end of file,返回值为EOF。

posted @ 2006-01-15 13:10 sopherwenxin 阅读(3197) | 评论 (0)编辑 收藏

女孩写给男孩的爱情脚本
Dear all:
result love(boy, girl)
{-
  if ( boy.有房() and boy.有车() )
   {-
    boy.set(nothing);
    return girl.嫁给(boy);
  }
  if ( girl.愿意等() )
  {-
   while( ! (boy.赚钱 > 100,000 and girl.感情 > 8 )
   {-
    for ( day=1; day <=365; day++)
    {-
     if ( day == 情人节 )
     if ( boy.givegirl(玫瑰) )
      girl.感情++;
      else
       girl.感情--;
        if( day == girl.生日)
     if ( boy.givegirl(玫瑰) )
        girl.感情++;
        else
        girl.感情--;
      boy.拼命赚钱();
      }
     }
    if ( boy.有房() and boy.有车() )
   {-
   boy.set(nothing);
 return girl.嫁给(boy);
 }
   年龄++;
   girl.感情--;
   }
}

posted @ 2006-01-15 11:40 sopherwenxin 阅读(459) | 评论 (0)编辑 收藏

2006年1月14日

  

问题5:导线交叉 

一个接线箱中上下各有n个端子,顶部的每个端子分别与底部的某个端子相连,形成一个完美匹配。

由于端子匹配的不同,导线会产生各种可能的交叉。在如下的例子中导线交叉点共有22个:

 t_2.bmp
编一个程序计算给定的连线方式下导线交叉点的总数。
 

输入:

第一行含1个整数,表示实例个数。

每个实例有一行输入,含n个整数,第i个整数表示与顶部第i个端子相连接的底部端子的编号(1in)。每个整数用空格隔开。 

输出:

第一行含1个整数,表示实例的序号

第二行输出交叉点的个数。

样例输入(采用上图中的例子)

1

10

8  7  4  2  5  1  9  3  10  6 

相应的正确输出样例:

1

22    

posted @ 2006-01-14 18:08 sopherwenxin 阅读(1257) | 评论 (7)编辑 收藏

2006年1月11日

Are You Ready?
——李嘉诚

当你们梦想伟大成功的时候,
你有没有刻苦的准备?
当你们有野心做领袖的时候,
你有没有服务于人的谦恭?
我们常常都想有所获得,
但我们有没有付出的情操?
我们都希望别人听到自己的说话,
我们有没有耐性聆听别人?
每一个人都希望自己快乐,
我们对失落、悲伤的人有没有怜悯?
每一个人都希望站在人前,
但我们是否知道什么时候甘为人后?
你们都知道自己追求什么,
你们知道自己需要什么吗?
我们常常只希望改变别人,
我们知道什么时候改变自己吗?
每一个人都懂得批判别人,
但不是每一个人都知道怎样自我反省。
大家都看重面子,
but do you know honor?
大家都希望拥有财富,
但你知道财富的意义吗?
各位朋友,相信你们都有各种激情,
但你知不知道什么是爱?

posted @ 2006-01-11 15:03 sopherwenxin 阅读(350) | 评论 (0)编辑 收藏