网络资源的拷贝粘贴 备份参考之用


13 April 2007

C++ std::string, std::wstring转换方法 [转载]

VS2005:C++ std::string, std::wstring转换方法

by Byte

随着VS2003升级到VS2005,很多以前熟悉的输入输出方式以及参数传递方式都不再有效
(参看
vs2003 vs2005代码升级要点)。

其中与字符串相关的内容是,

wcout
不再有效,默认参数传递方式由char*改成了wchar_t*等几个方面。
为了解决上面的这些问题,这篇文章里,我将给出几种
C++ std::stringstd::wstring相互转换的转换方法。
第一种方法:调用WideCharToMultiByte()和MultiByteToWideChar(),代码如下(关于详细的解释,可以参考《windows核心编程》):
#include
#include
using namespace std;
//Converting a WChar string to a Ansi string
std::string WChar2Ansi(LPCWSTR pwszSrc)
{
int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL);
if (nLen<= 0) return std::string("");
char* pszDst = new char[nLen];
if (NULL == pszDst) return std::string("");
WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL);
pszDst[nLen -1] = 0;
std::string strTemp(pszDst);
delete [] pszDst;
return strTemp;
}
string ws2s(wstring& inputws){ return WChar2Ansi(inputws.c_str()); }
//Converting a Ansi string to WChar string
std::wstring Ansi2WChar(LPCSTR pszSrc, int nLen)
{
int nSize = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszSrc, nLen, 0, 0);
if(nSize <= 0) return NULL;
WCHAR *pwszDst = new WCHAR[nSize+1];
if( NULL == pwszDst) return NULL;
MultiByteToWideChar(CP_ACP, 0,(LPCSTR)pszSrc, nLen, pwszDst, nSize);
pwszDst[nSize] = 0;
if( pwszDst[0] == 0xFEFF) // skip Oxfeff
for(int i = 0; i <>
pwszDst[i] = pwszDst[i+1];
wstring wcharString(pwszDst);
delete pwszDst;
return wcharString;
}
std::wstring s2ws(const string& s){ return Ansi2WChar(s.c_str(),s.size());}
第二种方法:采用ATL封装_bstr_t的过渡:(注,_bstr_是Microsoft Specific的,所以下面代码可以在VS2005通过,无移植性);
#include
#include
using namespace std;
#pragma comment(lib, "comsuppw.lib")
string ws2s(const wstring& ws);
wstring s2ws(const string& s);
string ws2s(const wstring& ws)
{
_bstr_t t = ws.c_str();
char* pchar = (char*)t;
string result = pchar;
return result;
}
wstring s2ws(const string& s)
{
_bstr_t t = s.c_str();
wchar_t* pwchar = (wchar_t*)t;
wstring result = pwchar;
return result;
}
第三种方法:使用CRT库的mbstowcs()函数和wcstombs()函数,平台无关,需设定locale。
#include
#include
using namespace std;
string ws2s(const wstring& ws)
{
string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C";
setlocale(LC_ALL, "chs");
const wchar_t* _Source = ws.c_str();
size_t _Dsize = 2 * ws.size() + 1;
char *_Dest = new char[_Dsize];
memset(_Dest,0,_Dsize);
wcstombs(_Dest,_Source,_Dsize);
string result = _Dest;
delete []_Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
wstring s2ws(const string& s)
{
setlocale(LC_ALL, "chs");
const char* _Source = s.c_str();
size_t _Dsize = s.size() + 1;
wchar_t *_Dest = new wchar_t[_Dsize];
wmemset(_Dest, 0, _Dsize);
mbstowcs(_Dest,_Source,_Dsize);
wstring result = _Dest;
delete []_Dest;
setlocale(LC_ALL, "C");
return result;
}
//第四种方法,标准C++转换方法:(待续)
//第五种方法,在C++中使用C#类库:(待续)

其中第四种,我的实现始终存在一些问题。 第五种,我只是知道有这么一种方案,没有时间去详细了解,算是给一些提示吧。

(转载自bianyongtao的msn space)

CString详细讲解 [转载]

CString详细讲解(zz)


前 言:串操作是编程中最常用也最基本的操作之一。 做为VC程序员,无论是菜鸟或高手都曾用过Cstring。而且好像实际编程中很难离得开它(虽然它不是标准C++中的库)。因为MFC中提供的这个类对 我们操作字串实在太方便了,CString不仅提供各种丰富的操作函数、操作符重载,使我们使用起串起来更象basic中那样直观;而且它还提供了动态内 存分配,使我们减少了多少字符串数组越界的隐患。但是,我们在使用过程中也体会到CString简直太容易出错了,而且有的不可捉摸。所以有许多高人站过 来,建议抛弃它。

在此,我个人认为:CString封装得确实很完美,它有许多优点,如“容易使用 ,功能强,动态分配内存,大量进行拷贝时它很能节省内存资源并且执行效率高,与标准C完全兼容,同时支持多字节与宽字节,由于有异常机制所以使用它安全方 便” 其实,使用过程中之所以容易出错,那是因为我们对它了解得还不够,特别是它的实现机制。因为我们中的大多数人,在工作中并不那么爱深入地去看关于它的文 档,何况它还是英文的。

由于前几天我在工作中遇到了一个本不是问题但却特别棘手、特别难解决而且莫名惊诧 的问题。好来最后发现是由于CString引发的。所以没办法,我把整个CString的实现全部看了一遍,才慌然大悟,并彻底弄清了问题的原因(这个问 题,我已在csdn上开贴)。在此,我想把我的一些关于CString的知识总结一番,以供他(她)人借鉴,也许其中有我理解上的错误,望发现者能通知 我,不胜感谢。

1. CString实现的机制.

CString是通过“引用”来管理串的,“引用”这个词我相信大家并不陌生,象 Window内核对象、COM对象等都是通过引用来实现的。而CString也是通过这样的机制来管理分配的内存块。实际上CString对象只有一个指 针成员变量,所以任何CString实例的长度只有4字节.

即: int len = sizeof(CString);//len等于4

这个指针指向一个相关的引用内存块,如图: CString str("abcd");

‘A’

‘B’

‘C’

‘D’

0

0x04040404 head部,为引用内存块相关信息

str 0x40404040

正因为如此,一个这样的内存块可被多个CString所引用,例如下列代码:

CString str("abcd");

CString a = str;

CString b(str);

CString c;

c = b;

上面代码的结果是:上面四个对象(str,a,b,c)中的成员变量指针有相同的值,都为0x40404040.而这块内存块怎么知道有多少个CString引用它呢?同样,它也会记录一些信息。如被引用数,串长度,分配内存长度。

这块引用内存块的结构定义如下:

struct CStringData

{

long nRefs; //表示有多少个CString 引用它. 4

int nDataLength; //串实际长度. 4

int nAllocLength; //总共分配的内存长度(不计这头部的12字节). 4

};

由于有了这些信息,CString就能正确地分配、管理、释放引用内存块。

如果你想在调试程序的时候获得这些信息。可以在Watch窗口键入下列表达式:

(CStringData*)((CStringData*)(this->m_pchData)-1)或

(CStringData*)((CStringData*)(str.m_pchData)-1)//str为指CString实例

正因为采用了这样的好机制,使得CString在大量拷贝时,不仅效率高,而且分配内存少。

2.LPCTSTR 与 GetBuffer(int nMinBufLength)

这两个函数提供了与标准C的兼容转换。在实际中使用频率很高,但却是最容易出错的地方。这两个函数实际上返回的都是指针,但它们有何区别呢?以及调用它们后,幕后是做了怎样的处理过程呢?

(1) LPCTSTR 它的执行过程其实很简单,只是返回引用内存块的串地址。 它是作为操作符重载提供的,所以在代码中有时可以隐式转换,而有时却需强制转制。如:

CString str;

const char* p = (LPCTSTR)str;

//假设有这样的一个函数,Test(const char* p); 你就可以这样调用

Test(str);//这里会隐式转换为LPCTSTR

(2) GetBuffer(int nMinBufLength) 它类似,也会返回一个指针,不过它有点差别,返回的是LPTSTR

(3) 这两者到底有何不同呢?我想告诉大家,其本质上完全不一样,一般说LPCTSTR转换后只应该当常量使用,或者做函数的入参;而GetBuffer(...)取出指针后,可以通过这个指针来修改里面的内容,或者做函数的出参。为什么呢?也许经常有这样的代码:

CString str("abcd");

char* p = (char*)(const char*)str;

p[2] = 'z';

其实,也许有这样的代码后,你的程序并没有错,而且程序也运行得挺好。但它却是非常危险的。再看

CString str("abcd");

CString test = str;

....

char* p = (char*)(const char*)str;

p[2] = 'z';

strcpy(p, "akfjaksjfakfakfakj");//这下完蛋了

你知道此时,test中的值是多少吗?答案是"abzd"。它也跟着改变了,这不是你 所期望发生的。但为什么会这样呢?你稍微想想就会明白,前面说过,因为CString是指向引用块的,str与test指向同一块地方,当你p[2]= 'z'后,当然test也会随着改变。所以用它做LPCTSTR做转换后,你只能去读这块数据,千万别去改变它的内容。

假如我想直接通过指针去修改数据的话,那怎样办呢?就是用GetBuffer(...).看下述代码:

CString str("abcd");

CString test = str;

....

char* p = str.GetBuffer(20);

p[2] = 'z'; // 执行到此,现在test中值却仍是"abcd"

strcpy(p, "akfjaksjfakfakfakj"); // 执行到此,现在test中值还是"abcd"

为什么会这样?其实GetBuffer(20)调用时,它实际上另外建立了一块新内块存,并分配20字节长度的buffer,而原来的内存块引用计数也相应减1. 所以执行代码后str与test是指向了两块不同的地方,所以相安无事。

(4) 不过这里还有一点注意事项:就是str.GetBuffer(20)后,str的分配长度为20,即指针p它所指向的buffer只有20字节长,给它赋 值时,切不可超过,否则灾难离你不远了;如果指定长度小于原来串长度,如GetBuffer(1),实际上它会分配4个字节长度(即原来串长度);另外, 当调用GetBuffer(...)后并改变其内容,一定要记得调用ReleaseBuffer(),这个函数会根据串内容来更新引用内存块的头部信息。

(5) 最后还有一注意事项,看下述代码:

char* p = NULL;

const char* q = NULL;

{

CString str = "abcd";

q = (LPCTSTR)str;

p = str.GetBuffer(20);

AfxMessageBox(q);// 合法的

strcpy(p, "this is test");//合法的,

}

AfxMessageBox(q);// 非法的,可能完蛋

strcpy(p, "this is test");//非法的,可能完蛋

这里要说的就是,当返回这些指针后, 如果CString对象生命结束,这些指针也相应无效。

3.拷贝 & 赋值 & "引用内存块" 什么时候释放?

下面演示一段代码执行过程

void Test()

{

CString str("abcd");

//str指向一引用内存块(引用内存块的引用计数为1,长度为4,分配长度为4)

CString a;

//a指向一初始数据状态,

a = str;

//a与str指向同一引用内存块(引用内存块的引用计数为2,长度为4,分配长度为4)

CString b(a);

//a、b与str指向同一引用内存块(引用内存块的引用计数为3,长度为4,分配长度为4)

{

LPCTSTR temp = (LPCTSTR)a;

//temp指向引用内存块的串首地址。(引用内存块的引用计数为3,长度为4,分配长度为4)

CString d = a;

//a、b、d与str指向同一引用内存块(引用内存块的引用计数为4, 长度为4,分配长度为4)

b = "testa";

//这条语句实际是调用CString::operator=(CString&)函数。 b指向一新分配的引用内存块。(新分配的引用内存块的 引用计数为1, 长度为5, 分配长度为5)

//同时原引用内存块引用计数减1. a、d与str仍指向原 引用内存块(引用内存块的引用计数为3,长度为4,分配长度为4)

}

//由于d生命结束,调用析构函数,导至引用计数减1(引用内存块的引用计数为2,长度为4,分配长度为4)

LPTSTR temp = a.GetBuffer(10);

//此语句也会导致重新分配新内存块。temp指向新分配引用内存块的串首地址(新 分配的引用内存块的引用计数为1,长度为0,分配长度为10)

//同时原引用内存块引用计数减1. 只有str仍 指向原引用内存块 (引用内存块的引用计数为1, 长度为4, 分配长度为4)

strcpy(temp, "temp");

//a指向的引用内存块的引用计数为1,长度为0,分配长度为10 a.ReleaseBuffer();//注意:a指向的引用内存块的引用计数为1,长度为4,分配长度为10

}

//执行到此,所有的局部变量生命周期都已结束。对象str a b 各自调用自己的析构构

//函数,所指向的引用内存块也相应减1

//注意,str a b 所分别指向的引用内存块的计数均为0,这导致所分配的内存块释放

通过观察上面执行过程,我们会发现CString虽然可以多个对象指向同一引用内块 存,但是它们在进行各种拷贝、赋值及改变串内容时,它的处理是很智能并且非常安全的,完全做到了互不干涉、互不影响。当然必须要求你的代码使用正确恰当, 特别是实际使用中会有更复杂的情况,如做函数参数、引用、及有时需保存到CStringList当中,如果哪怕有一小块地方使用不当,其结果也会导致发生 不可预知的错误

5 FreeExtra()的作用

看这段代码

(1) CString str("test");

(2) LPTSTR temp = str.GetBuffer(50);

(3) strcpy(temp, "there are 22 character");

(4) str.ReleaseBuffer();

(5) str.FreeExtra();

上面代码执行到第(4)行时,大家都知道str指向的引用内存块计数为1,长度为22,分配长度为50. 那么执行str.FreeExtra()时,它会释放所分配的多余的内存。(引用内存块计数为1,长度为22,分配长度为22)

6 Format(...) 与 FormatV(...)

这条语句在使用中是最容易出错的。因为它最富有技巧性,也相当灵活。在这里,我没打算 对它细细分析,实际上sprintf(...)怎么用,它就怎么用。我只提醒使用时需注意一点:就是它的参数的特殊性,由于编译器在编译时并不能去校验格 式串参数与对应的变元的类型及长度。所以你必须要注意,两者一定要对应上,

否则就会出错。如:

CString str;

int a = 12;

str.Format("first:%l, second: %s", a, "error");//result?试试

7 LockBuffer() 与 UnlockBuffer()

顾名思议,这两个函数的作用就是对引用内存块进行加锁及解锁。但使用它有什么作用及执行过它后对CString串有什么实质上的影响。其实挺简单,看下面代码:

(1) CString str("test");

(2) str.LockBuffer();

(3) CString temp = str;

(4) str.UnlockBuffer();

(5) str.LockBuffer();

(6) str = "error";

(7) str.ReleaseBuffer();

执行完(3)后,与通常情况下不同,temp与str并不指向同一引用内存块。你可以在watch窗口用这个表达式(CStringData*)((CStringData*)(str.m_pchData)-1)看看。

其实在msdn中有说明:

While in a locked state, the string is protected in two ways:

No other string can get a reference to the data in the locked string, even if that string is assigned to the locked string.

The locked string will never reference another string, even if that other string is copied to the locked string.

8 CString 只是处理串吗?

不对,CString不只是能操作串,而且还能处理内存块数据。功能完善吧!看这段代码

char p[20];

for(int loop=0; loop

{

p[loop] = 10-loop;

}

CString str((LPCTSTR)p, 20);

char temp[20];

memcpy(temp, str, str.GetLength());

str完全能够转载内存块p到内存块temp中。所以能用CString来处理二进制数据

8 AllocSysString()与SetSysString(BSTR*)

这两个函数提供了串与BSTR的转换。使用时须注意一点:当调用AllocSysString()后,须调用它SysFreeString(...)

9 参数的安全检验

在MFC中提供了多个宏来进行参数的安全检查,如:ASSERT. 其中在CString中也不例外,有许多这样的参数检验,其实这也说明了代码的安全性高,可有时我们会发现这很烦,也导致Debug与Release版本 不一样,如有时程序Debug通正常,而Release则程序崩溃;而有时恰相反,Debug不行,Release行。其实我个人认为,我们对 CString的使用过程中,应力求代码质量高,不能在Debug版本中出现任何断言框,哪怕release运行似乎看起来一切正常。但很不安全。如下代 码:

(1) CString str("test");

(2) str.LockBuffer();

(3) LPTSTR temp = str.GetBuffer(10);

(4) strcpy(temp, "error");

(5) str.ReleaseBuffer();

(6) str.ReleaseBuffer();//执行到此时,Debug版本会弹出错框

10 CString的异常处理

我只想强调一点:只有分配内存时,才有可能导致抛出CMemoryException.

同样,在msdn中的函数声明中,注有throw( CMemoryException)的函数都有重新分配或调整内存的可能。

11 跨模块时的Cstring。即一个DLL的接口函数中的参数为CString&时,它会发生怎样的现象。解答我遇到的问题。我的问题原来已经发贴,地址为:

http://www.csdn.net/expert/topic/741/741921.xml?temp=.2283136

构造一个这样CString对象时,如CString str,你可知道此时的str所指向的引用内存块吗?也许你会认为它指向NULL。其实不对,如果这样的话,CString所采用的引用机制管理内存块就 会有麻烦了,所以CString在构造一个空串的对象时,它会指向一个固定的初始化地址,这块数据的声明如下:

AFX_STATIC_DATA int _afxInitData[] = {-1,0,0,0};

简要描述概括一下:当某个CString对象串置空的话,如Empty(), CString a等,它的成员变量m_pchData就会指向_afxInitData这个变量的地址。当这个CString对象生命周期结束时,正常情况下它会去对所 指向的引用内存块计数减1,如果引用计数为0(即没有任何CString引用它时),则释放这块引用内存。而现在的情况是如果CString所指向的引用 内存块是初始化内存块时,则不会释放任何内存。

说了这么多,这与我遇到的问题有什么关系呢?其实关系大着呢?其真正原因就是如果 exe模块与dll模块有一个是static编译连接的话。那么这个CString初始化数据在exe模块与dll模块中有不同的地址,因为static 连接则会在本模块中有一份源代码的拷贝。另外一种情况,如果两个模块都是share连接的,CString的实现代码则在另一个单独的dll中实现,而 AFX_STATIC_DATA指定变量只装一次,所以两个模块中_afxInitData有相同的地址。

现在问题完全明白了吧!你可以自己去演示一下。

__declspec (dllexport) void test(CString& str)

{

str = "abdefakdfj";//如果是static连接,并且传入的str为空串的话,这里出错。

}

最后一点想法:写得这里,其实CString中还有许多技巧性的好东东,我并没去解释。如很多重载的操作符、查找等。我认为还是详细看看msdn,这样也许会比我讲的好多了。我只侧重那些可能会出错的情况。当然,如我上面叙述中有错误,敬请高手指点,不胜感谢!


msdn:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cstring_class_members.asp

CString/string/char *比较详解 [转载]

CString/string/char *比较详解

(一) 概述
string和CString均是字符串模板类,string为标准模板类(STL)定义的字符串类,已经纳入C++标准之中;
CString(typedef CStringT> CString)为Visual C++中最常用的字符串类,继承自CSimpleStringT类,主要应用在MFC和ATL编程中,主要数据类型有char(应用于ANSI), wchar_t(unicode),TCHAR(ANSI与unicode均可);
char*为C编程中最常用的字符串指针,一般以'\0'为结束标志;

(二) 构造
string是方便的,可以从几乎所有的字符串构造而来,包括CString和char*;
CString次之,可以从基本的一些字符串变量构造而来,包括char*等;
char*没有构造函数,仅可以赋值;
举例:
char* psz = “joise”;
CString cstr( psz );
string str( cstr );

(三) 运算符重载

a) operator=
string是最方便的,几乎可以直接用所有的字符串赋值,包括CString和char*;
CString次之,可以直接用些基本的字符串赋值,包括char*等;
char*只能由指针赋值,并且是极危险的操作,建议使用strcpy或者memcpy,而且char*在声明的时候如未赋初值建议先设为NULL,以避免野指针;
举例:
char *psz = NULL;
psz = new char[10]; //当然,以上的直接写成char *psz = new char[10];也是一样
memset( psz, 0, 10 );
strcpy( psz, “joise” );
CString cstr;
cstr = psz;
string str;
str = psz;
str = cstr;
delete []psz;

b) operator+
string与CString差不多,可以直接与char*进行加法,但不可以相互使用+运算符,即string str = str + cstr是非法的,须转换成char*;
char*没有+运算,只能使用strcat把两个指针连在一起;
举例:
char* psz = “joise”;
CString cstr = psz;
cstr = cstr + psz;
string str = psz;
str = str + str + psz;
strcat( psz, psz );
strcat( psz, cstr );//合法
strcat( psz, str );//非法,由此可见,CString可自动转换为const char*,而string不行

c) operator +=
string是最强大的,几乎可以与所有的字符串变量+=,包括CString和char*;
CString次之,可以与基本的一些字符串变量进行+=而来,包括char*等;
char*没有+=运算符,只能使用strcat把两个指针连在一起;

d) operator[]
CString最好,当越界时会抛出断言异常;
string与char*下标越界结果未定义;
举例:
char* psz = “joise”;
CString cstr = psz;
cout << cstr[8];
string str = psz;
cout << str[8];
cout << psz[8];

e) operator== 、operator!=、operator> 、operator< 、operator>= 、perator<=
CString与string之间不可以进行比较,但均可以与char*进行比较,并且比较的是值,而不是地址;
cout << ( psz == cstr );
cout << ( psz == str );
cout << ( str == psz );
cout << ( cstr == psz );//以上代码返回均为1


(四) 常用算法

a) 查找
作用 char* string CString
查找指定值 strchr
strstr
strrstr
strspn find Find
第一个匹配的值 fild_first_of FindOneOf
从后面开始查找 ReserveFind
指定匹配方式 find_if


注:find_if中是把范围内的值挨个代入匹配函数直至返回true
b) 比较
作用 char* string CString
查找指定值(区分大小写) strcmp
strncmp
strcoll
_strncoll operator<
operator>
operator<=
operator>=
operator==
operator!= Collate
Compare
查找指定值(不区分大小写) _stricmp
_strnicmp
_stricoll
_strnicoll CollateNoCase
CompareNoCase


注:返回值如果<0则前面的值小于后面的值,反之亦然
c) 替换
作用 char* string CString
查找指定值 _strset
_strnset replace
replace_copy
replace_copy_if
replace_if
Replace


d) 插入
作用 char* string CString
查找指定值 insert Insert






e) 增加
作用 char* string CString
动态增加值 strcat push
append Append
AppendChar
AppendFormat


f) 截取
作用 char* string CString
得到部分值 用下标操作 substr Left
Mid
Right
Truncate


g) 移除
作用 char* string CString
移除部份值 remove Remove
移除空白值 RemoveBlanks
注:此为ATL提供,非C函数 remove_if Trim
TrimLeft
TrimRigth


h) 转换大小写
作用 char* string CString
转换大小写 _strlwr
_strupr MakeLower
MakeUpper


i) 与其他类型转换
作用 char* string CString
转化为数字 atoi
atod
atof Format
转化为char* c_str GetBuffer
GetBufferSetLength


j) 格式化
作用 char* string CString
格式化 sprintf Format


k) 得到长度
作用 char* string CString
得到长度 strlen length GetLength
得到大小 size GetAllocLength


l) 判断为空
作用 char* string CString
判断是否为空 判断是否==NULL或者第一个字符是否是’\0’ empty IsEmpty


m) 重定义大小
作用 char* string CString
重定义大小 realloc
new resize GetBufferSetLength


n) 释放资源
作用 char* string CString
释放 free
delete (delete[]) ReleaseBuffer
ReleaseBufferSetLength


(五) 安全性
CString > string > char*
(六) 灵活性
CString > string >char*
(七) 可移植性
char* = string > CString


总结
综上所述,在MFC、ATL中使用字符串尽量使用CString,毕竟都是微软的孩子,各方面都比其它更有优势,而在非微软平台上或对移植性要求较高的场合推荐使用string,标准模板库提供了
那么强大的泛型算法,没必要再自己去造车轮。


Tags:cstring, string, char*

6 April 2007

Auction [算法题]

Category: Algorithms Title: Auction
Description:

Recently the auction house has introduced a new type of auction, the lowest price auction. In this new system, people compete for the lowest bid price, as opposed to what they did in the past. What an amazing thing! Now you could buy cool stuff with one penny. Your task is to write the software to automate this auction system.
First the auctioneer puts an upper limit on bid price for each item. Only positive price less than or equal to this price limit is a valid bid. For example, if the price limit is 100, then 1 to 100, inclusive, are all valid bid prices. Bidder can not put more than one bid for the same price on a same item. However they can put many bids on a same item, as long as the prices are different. After all bids are set, the auctioneer chooses the winner according to the following rules:
1. If any valid price comes from only one bidder, the price is a "unique bid". If there are unique bids, then the unique bid with the lowest price wins. This price is the winning price and the only bidder is the winning bidder.
2. If there are no unique bids, then the price with fewest bids is the winning bid. If there are more than one price which has the same lowest bid count, choose the lowest one. This price is the winning price. The bidder who puts this bid first is the winning bidder.
Given the price limit and all the bids that happen in order, you will determine the winning bidder and the winning price.
Input Description
The first line of each test case contains two integers: U (1 <= U <= 10,000), the price upper limit and M (1 <= M <= 100,000), the total number of bids. M lines follow, each of which presents a single bid. The bid contains the bidder's name (consecutive non-whitespace characters) and the price P (1 <= P <= U), separated with a single space. All bids in the input are guaranteed to be valid ones.
Output Description
For each test case, print the sentence "The winner is W." on the first line, and "The price is P." on the second. Replace W and P with the winning bidder’s name and the winning price.
Examples:
Sample Input

3 3
Alice 1
Bob 2
Carl 3

3 6
Alice 1
Alice 2
Alice 3
Bob 1
Bob 3
Carl 3
Sample Output
Case 1:
The winner is Alice.
The
Time Limitation: 2 s Memory Limitation: 32 MB
Score: 50 Points Language:

Zorro [算法题]


This puzzle has been in your puzzle list. Your score will not increase when you submit again.

Category: Algorithms Title: Zorro
Description:
Zorro is ready to modernize -- he is tired of hand drawing his giant "Z", and would like to add an educational element. So he wants you to write a program to draw a Z using the lower-case letters of the alphabet in order. If you run out of letters, just continue by following z with a.
Input

A positive integer(<=500) denoting the number of characters across the top of the Z. An input of 0 will indicate that Zorro is done. Output The Z, drawn in lowercase alphabetic characters. Each Z should be separated from the previous Z by at least one blank line.
Examples:

Sample:
Input:
3
0
Output:
abc
@d
efg
_____
Notice: the charactor '@' should be a space.
Time Limitation: 1 s Memory Limitation: 10 MB
Score: 30 Points Language:


5 April 2007

How many strings? [算法题]

Category: Data Structures Title: How many strings?
Description:

假 设有这样一种字符串,它们的长度不大于 26 ,而且若一个这样的字符串其长度为 m ,则这个字符串必定由 a, b, c ... z 中的前 m 个字母构成,同时我们保证每个字母出现且仅出现一次。比方说某个字符串长度为 5 ,那么它一定是由 a, b, c, d, e 这 5 个字母构成,不会多一个也不会少一个。嗯嗯,这样一来,一旦长度确定,这个字符串中有哪些字母也就确定了,唯一的区别就是这些字母的前后顺序而已。

现在我们用一个由大写字母 A 和 B 构成的序列来描述这类字符串里各个字母的前后顺序:

l 如果字母 b 在字母 a 的后面,那么序列的第一个字母就是 A (After),否则序列的第一个字母就是 B (Before);
l 如果字母 c 在字母 b 的后面,那么序列的第二个字母就是 A ,否则就是 B;
l 如果字母 d 在字母 c 的后面,那么 …… 不用多说了吧?直到这个字符串的结束。

这 规则甚是简单,不过有个问题就是同一个 AB 序列,可能有多个字符串都与之相符,比方说序列"ABA",就有"acdb"、"cadb"等等好几种可能性。说的专业一点,这一个序列实际上对应了一个 字符串集合。那么现在问题来了:给你一个这样的AB 序列,问你究竟有多少个不同的字符串能够与之相符?或者说这个序列对应的字符串集合有多大?注意,只要求个数,不要求枚举所有的字符串。

注:如果结果大于10亿就返回-1。

Examples:

注:每次测试只有一个AB字符串,输出的行尾无换行符。

INPUT:
A
AA
BBB
ABA
AAAB
ABABABA

OUTPUT:
1
1
1
5
4
1385
Time Limitation: 5 s Memory Limitation: 20 MB
Score: 80 Points Language:

谷歌拼音输入法使用了搜狗词库 [转载]

搜狗拼音输入法开发人员:谷歌拼音输入法使用了搜狗词库

来源于搜狗拼音开发人员的blog:
gpy的智能性和词库和sogou很相似.不 过出乎意料的一件事情是gpy居然也使用了sogou的词库,我们加在搜狗拼音中的彩蛋居然在gpy中也有(我,子健,mark,jerry的名字,基本 上都是生僻人名).这至少说明google这帮人够懒的.相应的,我们的很多词库错误也被原封不动的拿去了,例如冯巩的音标成了pinggong.但我们的一些错词他们没有,估计是有过再加工.这件事情值得记录一下,嚷了很久的“狼来了”终于成为事实,将来会有更多的竞争,当然不是什么坏事.

几点感受:

1)gpy界面延续了google产品的一贯风格,很典雅.当然,这个东西是仁者见仁智者见智的,没法说一定比sogou好.
2)gpy的一些功能,sogou不是不能做而是不敢做,怕被人骂流氓,十年怕井绳呀.不过google开了个头就好办了..
3)gpy的bug和sogou的bug很类似,估计也中了不少ms的道儿...
4) gpy的智能性和词库和sogou很相似.不过出乎意料的一件事情是gpy居然也使用了sogou的词库,我们加在搜狗拼音中的彩蛋居然在gpy中也有 (我,子健,mark,jerry的名字,基本上都是生僻人名).这至少说明google这帮人够懒的.相应的,我们的很多词库错误也被原封不动的拿去 了,例如冯巩的音标成了pinggong. 但我们的一些错词他们没有,估计是有过再加工.

5)很多细节功能方面sogou还是领先的,但gpy的起点很高, 不容忽视,是个强大的对手.

最后,感叹一下品牌效应.

有 人在网上发文说:在google,baidu和sogou上搜索“谷歌拼音”,google没有结果,baidu只有2条结果,sogou全部是最新的结 果(新闻和下载地址).结果大部分人回答:用news.google.com吧.在很多人的潜意识里面,google搜不出结果是你不会用,而不是 google做的不好.什么时候敝狗也有这样的品牌,睡着了都要笑...

此为blog文章,请投递者务必注明出处

4 April 2007

Wikipedia :: Walter Savage Landor

Walter Savage Landor

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Walter Savage Landor (January 30, 1775September 17, 1864) was an English writer and poet, eldest son of Walter Landor and his wife Elizabeth Savage.

Walter Savage Landor
Walter Savage Landor

Contents

[hide]

[edit] Early life

Walter Savage Landor was born in Warwick, England, the eldest son of Walter Landor, a physician, and his wife, Elizabeth Savage. His mother owned a considerable amount of property, to which her eldest son was heir.

He was sent to Rugby School, but was removed at the headmaster's request and studied privately with Mr. Langley, vicar of Ashbourne. In 1793 he entered Trinity College, Oxford. He adopted republican principles and in 1794 fired a gun at the windows of a Tory for whom he had an aversion. He was rusticated for a year, and, although the authorities were willing to condone the offence, he refused to return. The affair led to a quarrel with his father in which Landor expressed his intention of leaving home for ever. He was, however, reconciled with his family through the efforts of his friend Dorothea Lyttelton. He entered no profession, but his father allowed him £150 a year, and he was free to live at home or not, as he pleased.

[edit] South Wales

Landor settled in South Wales, returning home to Warwick for short visits. It was here that he became friendly with the family of Lord Aylmer, including his daughter, Rose, who Landor later immortalized in the poem, "Rose Aylmer". It was she who lent him the book in which he found a description of an Arabian Tale that inspired his poem, Gebir.

[edit] First Publication and Gebir

In 1793 appeared in a small volume, divided into three books, The Poems of Walter Savage Landor, and, in pamphlet form of nineteen pages, an anonymous Moral Epistle, respectfully dedicated to Earl Stanhope. No poet at the age of twenty ever had more vigour of style and fluency of verse; nor perhaps has any ever shown such masterly command of epigram and satire, made vivid and vital by the purest enthusiasm and most generous indignation.

Three years later appeared the first edition of the first great work which was to inscribe his name for ever among the great names in English poetry, Gebir.

The second edition of Gebir appeared in 1803, with a text corrected of grave errors and improved by magnificent additions. About the same time the whole poem was also published in a Latin form, which for might and melody of line, for power and perfection of language, must always dispute the palm of precedence with the English version. His father's death in 1802 put him in possession of an independent fortune. Landor settled in Bath. Here in 1808 he met Southey, and the mutual appreciation of the two poets led to a warm friendship.

[edit] Napoleonic Wars

In 1808, under an impulse not less heroic than that which was afterwards to lead Byron to a glorious death in redemption of Greece and his own good fame, Landor, then aged thirty-three, left England for Spain as a volunteer to serve in the national army against Napoleon at the head of a regiment raised and supported at his sole expense. After some three months campaigning came the affair of Cintra and its disasters; his troop, in the words of his biographer, dispersed or melted away, and he came back to England in as great a hurry as he had left it, but bringing with him the honorable recollection of a brave design unselfishly attempted.

The campaign also furnished the material in his memory for the sublimest poem published in our language, between the last masterpiece of Milton and the first masterpiece of Shelley, one equally worthy to stand unchallenged beside either for poetic perfection as well as moral majesty, the lofty tragedy of Count Julian, which appeared in 1812, without the name of its author. No comparable work is to be found in English poetry between the date of Samson Agoniites and the date of Prometheus Unbound; and with both these great works it has some points of greatness in common. The superhuman isolation of agony and endurance which encircles and exalts the hero is in each case expressed with equally appropriate magnificence of effect. The style of Count Julian, if somewhat deficient in dramatic ease and the fluency of natural dialogue, has such might and purity and majesty of speech as elsewhere we find only in Milton so long and so steadily sustained.

[edit] Marriage and separation

In May 1811 Landor had suddenly married Miss Julia Thuillier, with whose looks he had fallen in love at first sight in a ball-room at Bath; and in June they settled for a while at Llanthony Abbey in Monmouthshire, whence he was worried in three years time by the combined vexation of neighbors and tenants, lawyers and lords-lieutenant; not before much toil and money had been nobly wasted on attempts to improve the sterility of the land, to relieve the wretchedness and raise the condition of tIe peasantry. He left England for France at first, but after a brief residence at Tours took up his abode for three years at Como; and three more wandering years he passed, says his biographer, between Pisa and Pistoja, before he pitched his tent in Florence in 1821.

In 1835 he had an unfortunate difference with his wife which ended in a complete separation. In 1824 appeared the first series of his Imaginary Conversations, in 1826 the second edition, corrected and enlarged; a supplementary third volume was added in 1828; and in 1829 the second series was given to the world. Not until 1846 was a fresh instalment added, in the second volume of his collected and selected works.

[edit] Poetry

During the interval he had published his three other most famous and greatest books in prose: The Citation and Examination of William Shakespeare (1834), Pericles and Aspasia (1836), The Pentameron (1837). To the last of these was originally appended The Pentalogia, containing five of the very finest among his shorter studies in dramatic poetry. In 1847 he published his most important Latin work, Poemata et inscriptiones, comprising, with large additions, the main contents of two former volumes of idyllic, satiric, elegiac and lyric verse; and in the same golden year of his poetic life appeared the very crown and flower of its manifold labors, the Hellenics of Walter Savage Landor, enlarged and completed. Twelve years later this book was re-issued, with additions of more or less value, with alterations generally to be regretted, and with omissions invariably to be deplored.

In 1853 he put forth The Last Fruit off an Old Tree, containing fresh conversations, critical and controversial essays, miscellaneous epigrams, lyrics and occasional poems of various kind and merit, closing with Five Scenes on the martyrdom of Beatrice Cenci, unsurpassed even by their author himself for noble and heroic pathos, for subtle and genial, tragic and profound, ardent and compassionate insight into character, with consummate mastery of dramatic and spiritual truth. In 1857 he published Antony and Octavius: Scenes for the Study, twelve consecutive poems in dialogue which alone would suffice to place him high among the few great masters of historic drama.

In 1858 appeared a metrical miscellany bearing the title of Dry Sticks Fagoted by W. S. Landor, and containing among other things graver and lighter certain epigrammatic and satirical attacks which reinvolved him in the troubles of an action for libel; and in July of the same year he returned for the last six years of his life to Italy, which he had left for England in 1835. He was advised to make over his property to his family, on whom he was now dependent. They appear to have refused to make him an allowance unless he returned to England. By the exertions of Robert Browning an allowance was secured. Browning settled him first at Siena and then at Florence. Embittered and distracted by domestic dissensions, if brightened and relieved by the affection and veneration of friends and strangers, this final period of his troubled and splendid career came at last to a quiet end on September 17, 1864. In the preceding year he had published a last volume of Heroic Idyls, with Additional Poems, English and Latin, the better part of them well worthy to be indeed the last fruit of a genius which after a life of eighty-eight years had lost nothing of its majestic and pathetic power, its exquisite and exalted loveliness. He is buried under a laurel in the 'English' Cemetery, Florence, near the tomb of his friend, Elizabeth Barrett Browning. A statue of his wife can also be found in the 'English' Cemetery, above the tomb of their son, Arnold Savage Landor. Later, his Villa Gherardesca in Fiesole would become the home of the American Icelandic scholar Daniel Willard Fiske, who renamed it the 'Villa Landor'.

A complete list of Landor's writings, published or privately printed, in English, Latin and Italian, including pamphlets, fly-sheets and occasional newspaper correspondence on political or literary questions, it would be difficult to give anywhere and impossible to give here. From nineteen almost to ninety his intellectual and literary activity was indefatigably incessant; but, herein at least like Charles Lamb, whose cordial admiration he so cordially returned, he could not write a note of three lines which did not bear the mark of his Roman hand in its matchless and inimitable command of a style at once the most powerful and the purest of his age.

The one charge which can ever seriously be brought and maintained against it is that of such occasional obscurity or difficulty as may arise from excessive strictness in condensation of phrase and expurgation of matter not always superfluous, and sometimes almost indispensable. His English prose and his Latin verse are perhaps more frequently and more gravely liable to this charge than either his English verse or his Latin prose. At times it is well-nigh impossible for an eye less keen and swift, a scholarship less exquisite and ready than his own, to catch the precise direction and follow the perfect course of his rapid thought and radiant utterance.

This apparently studious pursuit and preference of the most terse and elliptic expression which could be found for anything he might have to say could not but occasionally make even so sovereign a master of two great languages appear dark with excess of light; but from no former master of either tongue in prose or verse was ever the quality of real obscurity, of loose and nebulous incertitude, more utterly alien or more naturally remote. There is nothing of cloud or fog about the path on which he leads us; but we feel now and then the want of a bridge or a handrail; we have to leap from point to point of narrative or argument withoit the usual help of a connecting plank. Even in his dramatic works, where least of all it should have been found, this lack of visible connection or sequence in details of thought or action is too often a source of sensible perplexity. In his noble trilogy on the history of Giovanna queen of Naples it is sometimes actually difficult to realize on a first reading what has happened or is happening, or how, or why, or by what agency a defect alone sufficient, but unhappily sufficient in itself, to explain the too general ignorance of a work so rich in subtle and noble treatment of character, so sure and strong in its grasp and rendering of high actions and high passions, so rich in humour and in pathos, so royally serene in its commanding power upon the tragic mainsprings of terror and of pity.

As a poet, he may be said on the whole to stand midway between Byron and Shelley--about as far above the former as below the latter. If we except Catullus and Simonides, it might be hard to match and it would be impossible to overmatch the flawless and blameless yet living and breathing beauty of his most perfect elegies, epigrams or epitaphs. As truly as prettily was he likened by Leigh Hunt to a stormy mountain pine which should produce lilies. His passionate compassion, his bitter and burning pity for all wrongs endured in all the world, found only their natural and inevitable outlet in his lifelong defence or advocacy of tyrannicide as the last resource of baffled justice, the last discharge of heroic duty. His tender and ardent love of children, of animals and of flowers makes fragrant alike the pages of his writing and the records of his life. He was as surely the most gentle and generous as the most headstrong and hot-headed of heroes or of men. Nor ever was any mans best work more thoroughly imbued and informed with evidence of his noblest qualities. His loyalty and liberality of heart were as inexhaustible as his bounty and beneficence of hand. Praise and encouragement, deserved or undeserved, came yet more readily to his lips than challenge or defiance.

Reviled and ridiculed by Lord Byron, he retorted on the offender living less readily and less warmly than he lamented and extolled him dead. On the noble dramatic works of his brother Robert (Robert Eyres Landor 1781 - 1869) he lavished sympathetic praise.

He was a classic, and no formalist; the wide range of his admiration had room for a genius so far from classical as Blake's. Nor in his own highest mood or method of creative as of critical work was he a classic only, in any narrow or exclusive sense of the term. On either side, immediately or hardly below his mighty masterpiece of Pericles and Aspasia, stand the two scarcely less beautiful and vivid studies of medieval Italy and Shakespearean England.

The very finest flower of his dialogues is probably to be found in the single volume Imaginary Conversations of Greeks and Romans; his command of passion and pathos may be tested by its success in the distilled and concentrated tragedy of Tiberius and Vipsania, where for once he shows a quality more proper to romantic than classical imagination: the subtle and sublime and terrible power to enter the dark vestibule of distraction, to throw the whole force of his fancy, the whole fire of his spirit, into the shadowing passion (as Shakespeare calls it) of gradually imminent insanity. Yet, if this and all other studies from ancient history or legend could be subtracted from the volume of his work, enough would be left whereon to rest the foundation of a fame which time could not sensibly impair.

Landor was affectionately adapted by Charles Dickens into the character Boythorn in Bleak House.

[edit] Bibliography

See The Works and Life of Walter Savage Landor (8 vols., 1846), the life being the work of John Forster. Another edition of his works (1891–1893), edited by C. G. Crump, comprises Imaginary Conversations, Poems, Dialogues in Verse and Epigrams and The Longer Prose Works. His Letters and other Unpublished Writings were edited by Stephen Wheeler (1897). There are many volumes of selections from his works, notably one (1882) for the Golden Treasury series, edited by Sidney Colvin, who also contributed the monograph on Landor (1881) in the English Men of Letters series. A bibliography of his works, many of which are very rare, is included in Sir Leslie Stephen's article on Landor in the Dictionary of National Biography (vol. xxxii., 1892).

[edit] External links

Wikiquote has a collection of quotations related to:
Wikisource has original text related to this article:

This article incorporates text from the Encyclopædia Britannica Eleventh Edition, a publication now in the public domain.

A peom from W.S.Landor

作者:君思无邪
日期:2007-3-30 15:10:26


英国诗人兰德(W.S.Landor)的同名小诗《生与死》:?

I strove with none,
for none was worth my strife;
Nature I loved,
and next to Nature, Art;
I warm'd both hands before the fire of Life;
It sinks;
and I am ready to depart.

杨绛将译作为:
我和谁都不争,和谁争我都不屑;我爱大自然,其次是艺术;我双手烤着,生命之火取暖;火萎了,我也准备走了。
李霁野译为:
我不和人争斗,因为没有人值得我争斗。我爱大自然,其次爱艺术;我在生命的火前,温暖我的双手;一旦生命的火消沉,我愿意长逝。
大师级的绿原则译作:
我不与人争,胜负均不值。我爱大自然,艺术在其次。且以生命之火,烘我的手。它一熄,我转身就走。

2 April 2007

Talk about Busy :: Lucy Kellaway

带着“黑莓”手机上床




我时不时地告诉我丈夫,自己是个处于精神崩溃边缘的女人,然后逐条列举我当日做的所有事情,以及第二天要做的事。

这是个冗长的单子:要写的文章、要阅读和发送的无聊信息、锅炉上某个指示灯令人不安地亮了,以及不小心遗忘在公共汽车上的一套儿童运动用品,等等。在我说完这些以后,我丈夫总以类似法官的口气说:“你的生活很幸福,而且非常充实。你不希望它变成其它任何样子。”

这远不是我想得到的回应,即“你真了不起啊!”,或者至少是“我能为你倒杯茶吗?”。然而,在这个问题上,更让我烦心的是,我怀疑他或许是正确的。我的忙碌或许不会使我精神崩溃,或许是它让我保持心智健全。

上 周,我这种猜疑有所加剧,原因是我读了一本专为那些有太多事情要做的人所写的自助指南,名字叫做《忙得发疯》(CrazyBusy)。该书的副标题是“过 度紧张、过度忙碌,即将崩溃”,这让我看到了一些希望——作者爱德华•哈洛韦尔医生(Edward M Hallowell MD)或许能够以一种我丈夫显然做不到的方式来理解我。

哈洛韦尔医生表示,忙碌这种东西是一种常见病。几乎所有人都过于忙碌。我们在毫无意义且让人上瘾的忙碌车轮上越来越快地运转,变得低效率、疲惫而暴躁。我们忙于对各种要求做出回应,却忽略了真正重要的事情。我们停止了思考,正在浪费自己的生命。

一天,一位患者走进哈洛韦尔医生的咨询室,询问如果她丈夫和她做爱时把“黑莓”手机(BlackBerry)放在她身边,这种做法是否正常,当时哈洛韦尔医生意识到,情况变得多么地糟糕。

他写道:“她丈夫的行为如果说不是病态的,至少也是无法接受的,而这位女士对此并不清楚,就在那一刻,我确信我们已经创造了一个新的世界。”

正 是读这本书的时候,我意识到,忙碌终究不是一个了不得的大问题,尽管围绕着它已经有许多感伤的废话。首先是这对夫妇的卧室习惯。他们做爱的时候在身边放什 么小东西,由他们自己决定。我看不出在床上放个“黑莓” 手机有什么不好,而且我猜有许多人都这么做。电话出现在卧室中已经有很长时间了,这无疑更让人厌恶,因为电话是会响的。

而从更普遍的意义来讲,整个命题就是错的——忙碌并非哈洛韦尔医生所说的现代生活的魔咒。尽管我自己疯狂忙碌,而且的确有很多时候心烦意乱、贻误事情,以及发送没有意义的信息,但我并未看到有任何迹象表明,这把我优先安排的事情搞糟了。

我在床边放了一本《诺桑觉寺》(Northanger Abbey)[有人会说,这与“黑莓”手机一样妨碍性生活]。这本书对于我是种提醒,告诉我人们在疯狂忙碌前通常所做的事情。

在 简•奥斯丁(Jane Austen)的时代,折磨中产阶级的社交强迫症甚至更令人烦恼:疯狂地无所事事。在巴斯(与乡村相比激动人心),女人们整个上午无所事事、然后下午去泵 房看着别人无所事事。而这种沉寂远非理清思路,产生伟大的思想;艾伦夫人总是不断地担心,是否要穿有图案的薄纱。

他们的生活,也没有 因为避免盲目追赶科技潮流而更好。相反:为了迷人的蒂尔尼(Tilney),凯瑟琳(Catherine)足足等了一个小时,最后跟着毫无可爱之处的索普 (Thorpe)走了。若蒂尔尼能够给她发送一条“晚点儿见面”的短信,那么这痛苦的一幕就永远不会发生。

一个表明忙碌优点的更新的 例子,是我一个朋友提出的。她是一位成功的职业母亲,上周末她前往一个健康农场,以逃避她那令人发狂的生活方式。当她从农场回来时,我问她,那儿有趣吗? 她回答,不。强迫自己闲下来,不仅毫无意义,还令人沮丧,尤其是她不得不安静地坐着,忍受着敷在脸上气味难闻的燕麦粥面膜。

哈洛韦尔 医生可能会对这个问题产生悲观的看法。他可能会说,她是一个面临戒断症的上瘾者:我们繁忙的生活,使我们如同踩着轮子的仓鼠,当我们从轮子上爬下来时,我 们会觉得一无是处,头晕眼花,并且绝望无助。不过,还有另一种更好的解释。忙得发疯(即使它是周期性的,也会让你觉得接近崩溃的边缘),总比坐在那里用粥 往脸上敷要好得多。

为此,我可以想出五条理由:

■忙碌意味着你很能办事,这是生活中最大的乐事之一。有句话非常正确,“如果你想完成某件事,就把它交给一个忙碌的人吧”。

■忙得发疯会让你觉得自己非常重要,而这种感觉总是很棒。

■忙得发疯令人兴奋。四处奔忙,可适当加快心跳次数。而如果像哈洛韦尔医生所警告的那样,这是一种药物,那又怎么样呢?它可没有高纯度可卡因那样的副作用。

■忙碌会激发正确的思维方式。我几乎所有的灵感(如果说还称得上灵感的话),都是在干其它事情——与别人聊天、骑脚踏车、将衣服放进滚筒甩干机里——时产生的。

■非常忙碌有助于避免错误的想法。它会挤掉一些无聊想法,例如:我的生活过得怎么样,我做人的意义是什么,以及我快要死掉了。这是忙碌的最大优点。正是因为这一点,当我想到今天要完成的所有事情时,我就会提醒自己:它们是我心灵的保护伞。
Google