一人拿一张百元钞票到商店买了25元的东西,店主由于手头没有零钱,便拿这张百元钞票到隔壁的小摊贩那里换了100元零钱,并找回了那人75元钱。那人拿着25元的东西和75元零钱走了。过了一会儿,隔壁小摊贩找到店主,说刚才店主拿来换零的百元钞票为假币。店主仔细一看,果然是假钞。店主只好又找了一张真的百元钞票给小摊贩。

问:在整个过程中,店主一共亏了多少钱财?

Tags: .
从单个源文件生成可执行程序

下面是一个保存在文件 helloworld.cpp 中一个简单的 C++ 程序的代码:

1
2
3
4
5
6
7
/* helloworld.cpp */
#include <iostream>
int main(int argc,char *argv[])
{
    std::cout << "hello, world\n";
    return(0);
}
Tags: ,.

地球人和外星人

Tags: ,.

circle-triangle

Tags: .

1、 并行计算:

并行计算是指同时对多个任务或多条指令、或对多个数据项进行处理。完成此项处理的计算机系统称为并行计算机系统,它是将多个处理器通过网络连接以一定的方式有序地组织起来。

Tags: .

方法一
先卸载当前的网络管理器netmanager:

sudo apt-get remove network-manager --purge

重启网络:

sudo /etc/init.d/networking restart

编辑配制文件:

sudo gedit /etc/network/interfaces

加入以下配置信息(修改为你自己的):

1
2
3
4
5
6
7
8
9
10
11
auto lo
auto eth0
iface lo inet loopback
iface eth0 inet static
address 192.168.0.1        #设置IP
netmask 255.255.255.0   #子网掩码
gateway 192.168.0.254    #网关
broadcast 192.168.0.255   #广播
mtu 1300
#wireless-key 3311220088
#wireless-essid ubuntu
Tags: ,.

 假设Linux系统中有一个文件名叫“-ee”,如果我们想对它进行操作,例如要删除它,按照一般的删除方法在命令行中输入rm -ee命令,界面会提示我们是“无效选项”(invalid option),原来由于文件名的第一个字符为“-”,Linux把文件名当作选项了,我们可以使用“–”符号来解决这个问题,输入“rm — -ee”命令便可顺利删除名为“-ee”的文件。如果是其他特殊字符的话可以在特殊字符前加一个“”符号,或者用双引号把整个文件名括起来。

Tags: ,.

简介

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! 需要包含de头文件
#include <sys/types.h>
#include <sys/stat.h>
 
int stat(const char *filename, struct stat *buf); //! prototype,原型
 
struct stat
{
    dev_t       st_dev;     /* ID of device containing file -文件所在设备的ID*/
    ino_t       st_ino;     /* inode number -inode节点号*/
    mode_t      st_mode;    /* protection -保护模式?*/
    nlink_t     st_nlink;   /* number of hard links -链向此文件的连接数(硬连接)*/
    uid_t       st_uid;     /* user ID of owner -user id*/
    gid_t       st_gid;     /* group ID of owner - group id*/
    dev_t       st_rdev;    /* device ID (if special file) -设备号,针对设备文件*/
    off_t       st_size;    /* total size, in bytes -文件大小,字节为单位*/
    blksize_t   st_blksize; /* blocksize for filesystem I/O -系统块的大小*/
    blkcnt_t    st_blocks;  /* number of blocks allocated -文件所占块数*/
    time_t      st_atime;   /* time of last access -最近存取时间*/
    time_t      st_mtime;   /* time of last modification -最近修改时间*/
    time_t      st_ctime;   /* time of last status change - */
};
Tags: ,.

Description:

There is a special card game that one who wins least rounds gets the money from people who win more. Suppose there are M people, including you, playing this game. First of all, each player gets N cards. The number on each card is a positive integer which is at most N*M. Additionally, the number of the cards is unique. The game consists of N rounds; for each round every player chooses one card to compare with cards from others. The player whose card with the biggest number wins the set, and then the next round begins. After N sets, when all the cards have been chosen, the player who has won the least rounds domains the game.

Tags: .

这是对C++高效编程的一个总结, 很有指导作用.

一、#include “filename.h”和#include 的区别

#include “filename.h”是指编译器将从当前工作目录上开始查找此文件
#include 是指编译器将从标准库目录中开始查找此文件

二、头文件的作用

加强安全检测
通过头文件可能方便地调用库功能,而不必关心其实现方式

三、* , &修饰符的位置

1
2
3
4
int *i,j; // better for read
 i = new int(0);
 j = 0;
 int *&y = i; // pointer's reference

对于*和&修饰符,为了避免误解,最好将修饰符紧靠变量名

四、if语句

不要将布尔变量与任何值进行比较,那会很容易出错的。
整形变量必须要有类型相同的值进行比较
浮点变量最好少比相等,可以通过求差与较小的数比较
指针变量要和NULL进行比较,不要和布尔型和整形比较

Tags: .