编程珠玑(第二版)2.1节第三个问题之变位词的实现

今天翻了翻编程珠玑这本书,整体而言还是比较有趣的。可以说给了读者另一种认识编程的角度吧。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

const int maxn = 1100;
vector<string> A[maxn];

map<string, int> hash;

int main()
{
	hash.clear();
	
	string str[110];
	int n = 0, k = 0;
	
	while(cin>>str[n] && str[n] != "END")
	{
		string t = str[n];
		sort(t.begin(), t.end());
		if(!hash[t]) hash[t] = ++k;
		n++;
	}
	
	for(int i = 0; i < n; i++)
	{
		string t = str[i];
		sort(t.begin(), t.end());
		A[hash[t]].push_back(str[i]);
	}
	
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < A[i].size(); j++)
		{
			cout<<A[i][j]<<" ";
		}
		cout<<endl;
	}
	
	system("pause");
	return 0;
}


/*
input:
	
ptos
pots
stop
tops
XXXX
END

output:
ptos pots stop tops
XXXX
*/

生命是一种过程

生命只是一种过程,老去的生命终有一天会被新生的生命所取代,而在这段旅程中,最重要的是每天的开心与充实。

Life is just like a journey. It is no doubt that there exist one day that the old things will be replace by the new things. So the meaning of life is that you are happy and feel fulfilled in this journey.

 

第一篇文字

第一篇文字就放这了,以后写写有关编程方面的东西,还有就是继续学习英语。

This is my first essay. In the future, I will write some essay about programming, Science fiction essays and some other things, more important is some reviews about books, and keep learning English.

main()
{
	printf("Hello World!\n");
	return 0;
}