An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence A, B, C, D implies that A < B, B < C and C < D. in this problem, we will give you a set of relations of the form A < B and ask you to determine whether a sorted order has been specified or not.
Input
Input consists of multiple problem instances. Each instance starts with a line containing two positive integers n and m. the first value indicated the number of objects to sort, where 2 <= n <= 26. The objects to be sorted will be the first n characters of the uppercase alphabet. The second value m indicates the number of relations of the form A < B which will be given in this problem instance. Next will be m lines, each containing one such relation consisting of three characters: an uppercase letter, the character "<" and a second uppercase letter. No letter will be outside the range of the first n letters of the alphabet. Values of n = m = 0 indicate end of input.
Output
For each problem instance, output consists of one line. This line should be one of the following three:
Sorted sequence determined after xxx relations: yyy...y.
Sorted sequence cannot be determined.
Inconsistency found after xxx relations.
where xxx is the number of relations processed at the time either a sorted sequence is determined or an inconsistency is found, whichever comes first, and yyy...y is the sorted, ascending sequence.
輸入樣例
4 6
A
A
A
B
26 1
A
輸出樣例
Sorted sequence determined after 4 relations: ABCD.
Inconsistency found after 2 relations.
Sorted sequence cannot be determined.
我們現(xiàn)在只看樣例:4和6的含義分別是:
4表示表達式中一共含有4個字符,也就是說我們需要排序的是4個樣例,6呢,就是需要用戶輸入6個表達式,我們根據(jù)這兩個數(shù)值和相應的表達式,去推算字符的先后順序
,可能會有三種結(jié)果,一種當然是排序成功,比如第一個輸入,一種是會有邏輯沖突,比如第二個輸入,一種就是條件不足,不能判斷
我的算法思想是這樣的,定義一個結(jié)構(gòu)體,該結(jié)構(gòu)體有三個變量,一個是key表示字符,一個是value,表示權(quán)重,一個就是布爾變量,表示該值是否已經(jīng)參加運算
1.根據(jù)用戶輸入初始換結(jié)構(gòu)體數(shù)組變量(chain_head),將相應的key值存到結(jié)構(gòu)體當中,value則是UNSET,布爾類型變量則是false,表示還未參加到運算當中,
2.接下來,計算第n個表達式(n初始化成0),我們獲取第n個表達式的第一個和第三個字符,分別獲得該key在結(jié)構(gòu)體數(shù)組中的索引,index_a和index_b,這樣需要比較的就是
chain_head[index_a]和chain_head[index_b]了,首先看下chain_head[index_a].value是否小于chain_head[index_b].value,如果小于,則不進行任何操作,繼續(xù)計算第n+1個
表達式,如果chain_head[index_a].value大于chain_head[index_b].value并且,chain_head[index_b].FirstApper=true(index_b的結(jié)構(gòu)體從未參加運算),則表示邏輯沖突,停
止循環(huán),輸出結(jié)構(gòu),如果chain_head[index_a].value==chain_head[index_b].value則chain_head[index_b].value=chain_head[index_a].value+1;即可,然后進行第n+1個表達
式的計算,繼續(xù)進行第二步的運算
3.清理現(xiàn)場,輸出結(jié)果
源代碼如下:
// Sort_It.cpp : 定義控制臺應用程序的入口點。
//
#include "stdafx.h"
#include
using namespace std;
/****************************************************************************************************************
***文件名稱:Sort_It.cpp
***文件描述:根據(jù)表達式對字符進行排序
****************************************************************************************************************/
typedef struct {
char key;
int value;
bool FirstApper;
}Key_Value;
Key_Value* chain_head=NULL;
int nCount=0;//需要排序的字符個數(shù)
int nCur_Count=0;//當前已經(jīng)賦值的個數(shù)
int result=0;
#define DONE 1
#define INCONSIST 2
#define UNENOUGH 3
#define UNSET 1
void operation(char key_a,char key_b);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///函數(shù)名稱:TestOver
///函數(shù)描述:檢測根據(jù)當前獲得信息,檢測是否已經(jīng)可以完成排序(value的值疊加,如果等于1,2,3的和則表示排序完成)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool TestOver(Key_Value* head)
{
int nSum_1=0,nSum=0;
for(int i=0;i
感谢您访问我们的网站,您可能还对以下资源感兴趣:
日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话
a∨无码视频手机版|黄色一级免费电影大全|国产福利视频导航|91大神在线精品|亚洲成人a片亚洲系列第一页|免费一级性爱大片|AA级黄色一级特黄成人大片|国产一区二区羞羞乱伦|人妻综合视频成人综合导航、|爱爱视频亚洲丝袜内射
国产一级片子色色亚洲网|日a在线播放国产熟妇性爱网|日本欧美成人电影|国产毛毛浓密茂盛AA性视频|日韩2024无码|欧美黄片免费看毛片电影|国产又大又粗又硬|最新国产黄色大片|日本亚洲三级视频|亚洲va欧美ⅴa在线
成人AV一区国内性视频|轮奸超碰精品福利|另类性爱亚洲性爱手机版|在线观看黄片一区|亚洲精品AⅤ一区二|久久亚洲婷婷五月婷a|99热这就是精品|日韩国产无码网址|日本不卡A V一区|99青草国产精品视频无码一区
