UVA10508 Word Morphing文本处理
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10508 Word Morphing文本处理相关的知识,希望对你有一定的参考价值。
Orlando was looking at his soup while his mother was in the kitchen. He was playing with the letters in his soup, and suddenly, he noticed that had a secret power. He could change the words morphing one word to another replacing the letter in a mysterious order.
Orlando has changed the letters of some words, you have to find an algorithm that find out the morphing order from the original word to the morphed one. The rules are simple:
- In each step you just can change one letter from the previous word.
- A letter can be changed just once
- All the letters in the word must change.
Input
The input is a file containing several unordered morphing series. For each one you have a line with the number of words, the number of letters in each word, next line is the first word, third line is the morphed one. The rest are the intermediate words unordered. The number of words are unlimited and all the words in each set have the same size. You can assume that all the characters are letters (capital or not).
Output
For each morphing you should print all the words in the correct order to convert the first one in the morphed one
Sample Input
6 5
remar
pitos
remas
remos
retos
ritos
5 4
pato
lisa
pata
pita
pisa
问题链接:UVA10508 Word Morphing
问题简述:给定若干长度相同的字符串,从起始位置开始,每次改变一个字符,使之称为另外一个字符串,求字符串的顺序。
问题分析:简单的文本处理问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10508 Word Morphing */
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
string s[N];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
while (cin >> n >> m) {
string last, curr;
cin >> last;
s[0] = last;
for (int i = 1; i < n; i++) {
int cnt = 0;
cin >> curr;
for (int j = 0; j < m; j++)
if (curr[j] != last[j]) cnt++;
s[cnt] = curr;
}
for (int i = 0; i < n; i++)
cout << s[i] << endl;
}
return 0;
}
以上是关于UVA10508 Word Morphing文本处理的主要内容,如果未能解决你的问题,请参考以下文章