Jabber ID(codeforce)

2023-11-08 11:38
文章标签 id codeforce jabber

本文主要是介绍Jabber ID(codeforce),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目连接:http://codeforces.com/contest/21/problem/A

题目大意:判断字符串是否符合要求

题目思路:直接处理字符串

A. Jabber ID
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where

  • <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive.
  • <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.
  • <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive.

There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.

Your task is to write program which checks if given string is a correct Jabber ID.

Input

The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.

Output

Print YES or NO.

Sample test(s)
Input
mike@codeforces.com
Output
YES
Input
john.smith@codeforces.ru/contest.icpc/12
Output
NO

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
bool flag=true;
void parse_user(string s)
{if(s.size()<1||s.size()>16){flag=false;return ;}for(int i=0; i<s.size(); i++){if(!isalpha(s[i])&&!isdigit(s[i])&&s[i]!='_'){flag=false;return ;}}
}
void parse_host(string s)
{if(s.size()<1||s.size()>32){flag=false;return ;}string cc;for(int i=0; i<s.size(); i++){if(s[i]=='.'){if(cc.size()<1||cc.size()>16){flag=false;return ;}for(int j=0; j<cc.size(); j++){if(!isalpha(cc[j])&&!isdigit(cc[j])&&cc[j]!='_'){flag=false;return ;}}cc="";}elsecc+=s[i];}if(cc.size()<1||cc.size()>16){flag=false;return ;}for(int j=0; j<cc.size(); j++){if(!isalpha(cc[j])&&!isdigit(cc[j])&&cc[j]!='_'){flag=false;return ;}}
}
void parse_res(string s)
{if(s.size()<1||s.size()>16)flag=false;for(int i=0; i<s.size(); i++){if(!isalpha(s[i])&&!isdigit(s[i])&&s[i]!='_'){flag=false;return ;}}
}
int main()
{string str;string username,hostname,resource;while(cin>>str){flag=true;int cur=0;while(cur<str.size()&&str[cur]!='@'){username+=str[cur];cur++;}if(cur>=str.size()){flag=false;}parse_user(username);cur++;while(cur<str.size()&&str[cur]!='/'){hostname+=str[cur];cur++;}parse_host(hostname);if(cur<str.size()){cur++;while(cur<str.size()){resource+=str[cur];cur++;}parse_res(resource);}if(flag)printf("YES\n");else printf("NO\n");}return 0;
}


这篇关于Jabber ID(codeforce)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/369598

相关文章

Springboot3+将ID转为JSON字符串的详细配置方案

《Springboot3+将ID转为JSON字符串的详细配置方案》:本文主要介绍纯后端实现Long/BigIntegerID转为JSON字符串的详细配置方案,s基于SpringBoot3+和Spr... 目录1. 添加依赖2. 全局 Jackson 配置3. 精准控制(可选)4. OpenAPI (Spri

MySQL查看表的最后一个ID的常见方法

《MySQL查看表的最后一个ID的常见方法》在使用MySQL数据库时,我们经常会遇到需要查看表中最后一个id值的场景,无论是为了调试、数据分析还是其他用途,了解如何快速获取最后一个id都是非常实用的技... 目录背景介绍方法一:使用MAX()函数示例代码解释适用场景方法二:按id降序排序并取第一条示例代码解

使用雪花算法产生id导致前端精度缺失问题解决方案

《使用雪花算法产生id导致前端精度缺失问题解决方案》雪花算法由Twitter提出,设计目的是生成唯一的、递增的ID,下面:本文主要介绍使用雪花算法产生id导致前端精度缺失问题的解决方案,文中通过代... 目录一、问题根源二、解决方案1. 全局配置Jackson序列化规则2. 实体类必须使用Long封装类3.

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

mysql数据库重置表主键id的实现

《mysql数据库重置表主键id的实现》在我们的开发过程中,难免在做测试的时候会生成一些杂乱无章的SQL主键数据,本文主要介绍了mysql数据库重置表主键id的实现,具有一定的参考价值,感兴趣的可以了... 目录关键语法演示案例在我们的开发过程中,难免在做测试的时候会生成一些杂乱无章的SQL主键数据,当我们

mysql8.0无备份通过idb文件恢复数据的方法、idb文件修复和tablespace id不一致处理

《mysql8.0无备份通过idb文件恢复数据的方法、idb文件修复和tablespaceid不一致处理》文章描述了公司服务器断电后数据库故障的过程,作者通过查看错误日志、重新初始化数据目录、恢复备... 周末突然接到一位一年多没联系的妹妹打来电话,“刘哥,快来救救我”,我脑海瞬间冒出妙瓦底,电信火苲马扁.

4-4.Andorid Camera 之简化编码模板(获取摄像头 ID、选择最优预览尺寸)

一、Camera 简化思路 在 Camera 的开发中,其实我们通常只关注打开相机、图像预览和关闭相机,其他的步骤我们不应该花费太多的精力 为此,应该提供一个工具类,它有处理相机的一些基本工具方法,包括获取摄像头 ID、选择最优预览尺寸以及打印相机参数信息 二、Camera 工具类 CameraIdResult.java public class CameraIdResult {

集群环境下为雪花算法生成全局唯一机器ID策略

雪花算法是生成数据id非常好的一种方式,机器id是雪花算法不可分割的一部分。但是对于集群应用,让不同的机器自动产生不同的机器id传统做法就是针对每一个机器进行单独配置,但这样做不利于集群水平扩展,且操作过程非常复杂,所以每一个机器在集群环境下是一个头疼的问题。现在借助spring+redis,给出一种策略,支持随意水平扩展,肥肠好用。 大致策略分为4步: 1.对机器ip进行hash,对某一个(大于

在实现回显功能模块的时候,把ID设置成全局变量了

在hsapprove.jsp中: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><script type="text/javascript">function edittodayhs(hsid){//alert(hsid);//

PL/SQL工具创建Oracle数据库表,实现id字段的自动递增

通过PL/SQL工具,创建Oracle数据库表,如何实现字段ID自动递增; Oracle的自增需要依靠序列和触发器共同实现 比如:先创建一个表 create table test (id int primary key, name varchar2(10)); 创建一个序列 create sequence test_seq increment by 1 start with 1  min