北京林业大学“计蒜客”杯程序设计竞赛 网络赛 D-A letter from Chensg【最长公共子序列LCS】

Can it really be 2 years since I first saw you? I still remember, vividly, 2 years ago, from the moment I saw you smile, as you were walking out of the classroom and turned your head back, with the soft sunset glow shining on your rosy cheek, I knew, I knew that I was already drunk on you. Then, after several months' observation and prying, your grace and your wisdom, your attitude to life and your aspiration for future were all strongly impressed on my memory. You were the glamorous and sunny girl whom I always dream of to share the rest of my life with. Alas, actually you were far beyond my wildest dreams and I had no idea about how to bridge that gulf between you and me. So I schemed nothing but to wait, to wait for an appropriate opportunity. Till now, I realize I am such an idiot that one should create the opportunity and seize it instead of just waiting?

Nowadays, you are planning to fly far far away, to pursue your future and fulfill your dreams. Perhaps we will not speak with each other very often if without fate and luck. Sometimes, I wandered around corridor hoping to meet you there by chance. But contradictorily, your appearance must quicken my heartbeat and my clumsy tongue might be not able to belch out a word. I cannot remember how many times I have passed your dormitory , and each time aspired to see you appear in the corridor. I cannot remember how many times this idea comes to my mind: call her out to have dinner or at least a conversation. But each time, thinking of your excellence and my commonness, the predominance of timidity over courage drove me leave silently?

Graduation, means the end of life in university, the end of these glorious, romantic years. Your lovely smile which is my original incentive to work hard and this unrequited love will be both sealed as a memory in the deep of my heart and my mind. Graduation, also means a start of new life, a footprint on the way to bright prospect. I truly hope you will be happy everyday abroad and everything goes well. Meanwhile, I will try to get out from puerility and become more sophisticated. To pursue my own love and happiness here in reality will be my ideal I never desert?

Good luck, my princess!?

If someday, somewhere, we have a chance to gather, even as gray-haired man and woman, at that time, I hope we can be good friends to share this memory proudly to relight the youthful and joyful emotions. If this chance never comes, I wish I were the stars in the sky and twinkling in your window, to bless you far away, as friends, to accompany you every night, sharing the sweet dreams or going through the nightmares together?

Here comes the problem: Assume the star is represented by a string sequence only including four different characters 'S', 'T', 'A' and 'R'. Of course,each character will appear many times.Your task is to write a program that will find commonalities amongst string sequces. Given a set of star sequences,Please determine the longest common subsequence that occurs in all of the sequences.

Input:

Input to this problem will begin with a line containing a single integer n indicating the number of datasets. Each dataset consists of the following components:

A single positive integer mm indicating the number of string sequences in this dataset. m lines each containing a single sequence consisting of 6060 characters, 2 \leq m \leq 102m10.

Output:

For each dataset in the input, output the longest subsequence common to all of the given sequences. If the longest common subsequence is less than three characters in length, display the string "No significant commonalities" instead. If multiple subsequences of the same longest length exist, output only the subsequence that comes first in alphabetical order.

样例1

输入:

3
2
SATARRASATARRASATARRASATARRASATARRASATARRASATARRASATARRASATA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
SATARRASATARRASATARRASATARRASATARRASATARRASATARRASATARRASATA
SATARTASATARTASATARTASATARTAAASSAAASSSAAAASSSSAAAAASSSSSAAAA
SATARRASATARRASATARRASATARRAAASSAAASSSAAAASSSSAAAAASSSSSAAAA
3
RATRATRATRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
ARATRATRATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AARATRATRATTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

输出:

No significant commonalities
ASATAR
RATRATRAT

解题思路:

最长公共子序列。

#include <iostream>  
#include <string>
using namespace std; 

string getLCSLength(string &s, string &t);

int main()
{
	int t; scanf("%d", &t);
	while(t--)
	{
		string s, b;
		int n;  scanf("%d", &n); 
		cin >>s;
		for(int i=1;  i<n; i++)
		{
			cin >>b;
			s=getLCSLength(s, b);
		}
		if(s.length()< 3)
			printf("No significant commonalities\n");
		else
		cout << s<< endl;
	}
	return 0;
}

string getLCSLength(string &s, string &t)
{
	int p = s.length();
	int q = t.length();

	string **num = new string *[p];  
    for(int i=0;i<p;i++)    
    {    
        num[i] = new string[q];  
    }   

	char char1 = '\0';
	char char2 = '\0';

	int len = 0;
	string lcs = "" ;

	for(int i=0; i<p; i++)
	{
		for (int j=0; j<t.length(); j++)
		{
			char1 = s.at(i);
			char2 = t.at(j);
			if(char1!=char2)
			{
				num[i][j] = "" ;
			}
			else
			{
				if (i==0||j==0)
				{
					num[i][j]=char1;
				}
				else
				{
					num[i][j]=num[i-1][j-1]+char1;
				}
				if(num[i][j].length()>len)
				{
					len = num[i][j].length() ;
					lcs = num[i][j];
				}
				else if(num[i][j].length()==len)
				{
					lcs =num[i][j]; 
					//lcs = lcs + "," + num[i][j];
				}
			}
		}
	}

	for(int i=0;i<p;i++)    
    {    
        delete[] num[i]; 
    } 
	delete[] num;

	return lcs;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自动控制节水灌溉技术的高低代表着农业现代化的发展状况,灌溉系统自动化水平较低是制约我国高效农业发展的主要原因。本文就此问题研究了单片机控制的滴灌节水灌溉系统,该系统可对不同土壤的湿度进行监控,并按照作物对土壤湿度的要求进行适时、适量灌水,其核心是单片机和PC机构成的控制部分,主要对土壤湿度与灌水量之间的关系、灌溉控制技术及设备系统的硬件、软件编程各个部分进行了深入的研究。 单片机控制部分采用上下位机的形式。下位机硬件部分选用AT89C51单片机为核心,主要由土壤湿度传感器,信号处理电路,显示电路,输出控制电路,故障报警电路等组成,软件选用汇编语言编程。上位机选用586型以上PC机,通过MAX232芯片实现同下位机的电平转换功能,上下位机之间通过串行通信方式进行数据的双向传输,软件选用VB高级编程语言以建立友好的人机界面。系统主要具有以下功能:可在PC机提供的人机对话界面上设置作物要求的土壤湿度相关参数;单片机可将土壤湿度传感器检测到的土壤湿度模拟量转换成数字量,显示于LED显示器上,同时单片机可采用串行通信方式将此湿度值传输到PC机上;PC机通过其内设程序算出所需的灌水量和灌水时间,且显示于界面上,并将有关的灌水信息反馈给单片机,若需灌水,则单片机系统启动鸣音报警,发出灌水信号,并经放大驱动设备,开启电磁阀进行倒时定时灌水,若不需灌水,即PC机上显示的灌水量和灌水时间均为0,系统不进行灌水。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值