1133. SPAM

本文介绍了一种从HTML文本中提取有效电子邮件地址的方法,并提供了一个使用C++实现的具体示例。该方法通过扫描文本查找'@'符号并验证其前后字符串的有效性来实现。

Constraints

Time Limit: 10 secs, Memory Limit: 32 MB

Description

You never had any friends, and don't really want any anyways, and so you have decided to collect email addresses from web pages for direct e-mail advertising.

The text delivered to a web browser is usually marked up HTML, which may contain email addresses of the form:


user@server

¨         Both user and server are of the form alpha.numeric.with.dots. By alpha.numeric.with.dots, we mean a sequence of one or more characters which are alphabetic (A-Z,a-z), numeric (0-9), hyphens (-), underbars (_) and/or periods (.), with the following restrictions on periods:

n         The sequence neither starts nor ends with a period.

n         No periods are adjacent.

¨         Email addresses are preceded by the beginning of the file, or some character other than a letter (A-Z,a-z), digit (0-9), hyphen (-), or underbar (_).

¨         Email addresses are succeeded by the end of the file, or some character other than a letter (A-Z,a-z), digit (0-9), hyphen (-), or underbar (_).

¨         If the scanned text contains a sequence of the form


first@second@third

Then the output should contain first@second and second@third as email addresses. In a longer run, each pair split by an @-sign should appear as an email address in the output.

The point of this problem is to extract and record the email addresses embedded in other text.

Input

The input file will contain zero or more lines of ASCII text.

Output

Other than the standard leader and trailer, the output file has each email address found in the input file in the order it was found (duplicates not removed).

Sample Input

bob@banks.com wrote:
What does <tt>x=7</tt> mean for this problem?  For
example,

..a@a@aa@aaa@aaa..a@a@aa@aaa@aaa..a@a..@a...a@..@..

this scrolling @-example from jim@jones.com

Sample Outp

bob@banks.com
a@a
a@aa
aa@aaa
aaa@aaa
a@a
a@aa
aa@aaa
aaa@aaa
a@a
jim@jones.com
这道题的代码的关键是找到字符@,然后再观察@前后的字符串是否满足条件要求,如果满足,就输出,同时,因为题目的要求是输入无限,所以我采取的方法是用getline函数读入一整行字符串,逐行处理。
Accept的代码如下:
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

int main()
{
	string s;
	while(getline(cin,s))
	{
		int a[100],k=0;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='@')
			{
				a[k]=i;
				k++;
			}
		}
		int l;
		for(int b=0;b<k;b++)
		{
			int count1=0,count2=0;
			if(b==0)
			   l=0;
			else
			   l=a[b-1];
			for(int i=a[b]-1;i>=l;i--)
			{
				if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z')||(s[i]>='0'&&s[i]<='9')||s[i]=='-'||s[i]=='_') 
		        {
		             	
			        count1++;
				}
				else if(s[i]=='.')
				{
					if(i==l-1)
			  			break;
					else if((s[i-1]>='A'&&s[i-1]<='Z')||(s[i-1]>='a'&&s[i-1]<='z')||(s[i-1]>='0'&&s[i-1]<='9')||s[i-1]                                                =='-'||s[i-1]=='_')
			   			count1++;
			   		else 
			   			break;
				}
				else
					break;
			}
			int la;
			if(b==k-1)
			   la=s.size();
			else
			   la=a[b+1];
			for(int i=a[b]+1;i<la;i++)
			{
				if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z')||(s[i]>='0'&&s[i]<='9')||s[i]=='-'||s[i]=='_') 
				{
					count2++;
				}
				else if(s[i]=='.')
				{
					if(i==la-1)
		    			break;
				    else if((s[i+1]>='A'&&s[i+1]<='Z')||(s[i+1]>='a'&&s[i+1]<='z')||(s[i+1]>='0'&&s[i+1]<='9')||s[i+1]=='-                                             '||s[i+1]=='_')
		    			count2++;
		    		else 
		    		   break;
				}
				else
	   				break;
			}
			if(count1>0&&count2>0)
			{
				for(int k=a[b]-count1;k<=a[b]+count2;k++)
				{
				   	cout<<s[k]; 
				}
				cout<<endl;
			}
		}
	}
	return 0;
}
思路:先遍历一次字符串,用一个数组记录下‘@’的位置,然后用循环遍历@的前后字符串,如果满足要求,则输出。
【四轴飞行器】非线性三自由度四轴飞行器模拟器研究(Matlab代码实现)内容概要:本文围绕非线性三自由度四轴飞行器模拟器的研究展开,重点介绍了基于Matlab的建模与仿真方法。通过对四轴飞行器的动力学特性进行分析,构建了非线性状态空间模型,并实现了姿态与位置的动态模拟。研究涵盖了飞行器运动方程的建立、控制系统设计及数值仿真验证等环节,突出非线性系统的精确建模与仿真优势,有助于深入理解飞行器在复杂工况下的行为特征。此外,文中还提到了多种配套技术如PID控制、状态估计与路径规划等,展示了Matlab在航空航天仿真中的综合应用能力。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的高校学生、科研人员及从事无人机系统开发的工程技术人员,尤其适合研究生及以上层次的研究者。; 使用场景及目标:①用于四轴飞行器控制系统的设计与验证,支持算法快速原型开发;②作为教学工具帮助理解非线性动力学系统建模与仿真过程;③支撑科研项目中对飞行器姿态控制、轨迹跟踪等问题的深入研究; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注动力学建模与控制模块的实现细节,同时可延伸学习文档中提及的PID控制、状态估计等相关技术内容,以全面提升系统仿真与分析能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值