POJ 1318 Word Amalgamation (简单题)

【题意简述】:首先第一串“XX……”之前的是所谓的字典,然后在它之后的就是我们要查的字串。现在让我们逐个求出这些要查的字串排列后和字典中的字串相同的有哪些,输出出来,没有的话就输出:NOT AVALLID WORD

【分析】:理解很简单,我们只需分别对字典中的这些字符串,和我们要查的这些字符串,每一个都排序,然后按位比较,每一位都是相同的那就输出出来就好了。

#include<iostream>
using namespace std;

int n;
char word[100][10],sorted[200][10];

int cmp_char(const void* _a,const void* _b)
{
	char* a = (char*)_a;
	char* b = (char*) _b;
	return *a - *b;
}

int cmp_string(const void* _a,const void* _b)
{
	char* b = (char*)_b;
	char* a = (char*)_a;
	return strcmp(a,b);
}

int main()
{
	n = 0;
	for(;;)
	{
		cin>>word[n];
		if(word[n][0] == 'X') break;
		n++;
	}
	qsort(word,n,sizeof(word[0]),cmp_string);
	for(int i = 0;i<n;i++)
	{
		strcpy(sorted[i],word[i]);
		qsort(sorted[i],strlen(sorted[i]),sizeof(char),cmp_char);
	}

	char s[10];
	while(cin>>s)
	{
		if(strcmp(s,"XXXXXX") == 0) break;
		qsort(s,strlen(s),sizeof(char),cmp_char);
		int found = 0;
		for(int i = 0;i<n;i++)
			if(strcmp(sorted[i],s) == 0)
			{
				found = 1;
				cout<<word[i]<<endl;
			}
		if(!found) cout<<"NOT A VALID WORD"<<endl;
		cout<<"******"<<endl;
	}
	return 0;
}
时间: 2024-10-03 14:56:35

POJ 1318 Word Amalgamation (简单题)的相关文章

POJ 1318 Word Amalgamation结题报告

Description In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but in order to find the letters that appear in the answer it is necessary to unscramble four words. Your

POJ 1318 Word Amalgamation (字符串 STL大水)

Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8665   Accepted: 4172 Description In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but

poj 1318 Word Amalgamation

Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 Description In millions of newspapers across the United States there is a word game called Jumble. The object of this game is to solve a riddle, but

POJ 2051 argus(简单题,堆排序or优先队列)

又是一道数据结构题,使用堆来进行权值调整和排序,每次调整都是o(n)的复杂度,非常高效. 第一眼看题觉得可以用优先队列来做,应该也很简单. 事实上多数优先队列都是通过堆来实现的. 写的时候还是出了一些问题: 1.二叉树根节点下标显然不能为0: 2.限界之后若出现扩界要小心: 3.在迭代循环比较的时候,尤其注意到底比较的是谁,别把自己绕晕了. ac代码: #include<iostream> #include<cstdio> #include<cstdlib> #incl

poj 1847 最短路简单题,dijkstra

1.poj  1847  Tram   最短路 2.总结:用dijkstra做的,算出a到其它各个点要改向的次数.其它应该也可以. 题意: 有点难懂.n个结点,每个点可通向ki个相邻点,默认指向第一个相邻点,可以改变指向.求一条从A到B的路,使用最少改变路上点的指向的次数. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm>

POJ 3619 Speed Reading(简单题)

[题意简述]:有K头牛,N页书,每次第i头牛每分钟只能读Si页书,连续读Ti分钟,之后休息Ri分钟.现在问我们第i头牛花费多少时间可以读完这N页书. [分析]:简单的模拟 //220K 32Ms #include<iostream> #include<cmath> using namespace std; int main() { double N,K,Si,Ti,Ri; cin>>N>>K; double a = N; for(int i = 0;i<

poj 2955 Brackets dp简单题

//poj 2955 //sep9 #include <iostream> using namespace std; char s[128]; int dp[128][128]; int n; int rec(int l,int r) { if(dp[l][r]!=-1) return dp[l][r]; if(l==r) return dp[l][r]=0; if(l+1==r){ if(s[l]=='('&&s[r]==')') return dp[l][r]=2; if(

poj 3414 Pots(BFS)(简单题)

Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11551   Accepted: 4900   Special Judge Description You are given two pots, having the volume of A and B liters respectively. The following operations can be performed: FILL(i)        f

POJ 2575 Jolly Jumpers(简单题)

[题意简述]:将数列中相邻的两个数做差,判断得到的绝对值是否是1,2,--,n-1,如果是的话,则是Jolly ,否则not jolly. [分析]:开始时没有仔细看题,没有看到时相邻的两个数做差,以为任意两两做差. 而后重新分析题目后,解决了这道题目,我们可以使用一个标志数组来帮助我们储存得到的做差的绝对值的值,最后,我们只需要扫描一下这个数组看是否从1,2,--,n-1都有值与之相对应. 详见代码: // 324K 47Ms #include<iostream> #include<c