Content

有一个字符串 \(s\),它满足以下要求:

  • 只包含 .@ 和小写字母。
  • 不以 . 为开头或者结尾。
  • 不以 @ 为开头或者结尾,并只能包含一个 @

请将其进行如下操作,使得这个字符串长度最小:

  • 将子串 dot 转化为 .
  • 将子串 at 转化为 @

数据范围:\(1\leqslant |s|\leqslant 100\)。

Solution

模拟就好,其实不需要什么 STL 里面的高级函数(只有一个 \(\texttt{size}\) 函数)。

首先得要找到子串 \(\texttt{dot}\) 和 \(\texttt{at}\) 的位置,尤其要注意的是 @ 最多只能用一次,所以开个变量判断一下。还有不能够在开头和结尾出现 . 或者 @

Code

#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; int atflag;
string s; int main() {
cin >> s;
int len = s.size();
for(int i = 0; i < len;) {
if(i > 0 && i < len - 3 && s[i] == 'd' && s[i + 1] == 'o' && s[i + 2] == 't') {
printf(".");
i += 3;
} else if(i > 0 && i < len - 2 && s[i] == 'a' && s[i + 1] == 't' && !atflag) {
printf("@");
i += 2;
atflag = 1;
} else {
printf("%c", s[i]);
++i;
}
}
return 0;
}

CF41C Email address 题解的更多相关文章

  1. 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions

    Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...

  2. Git坑点——remote: error: GH007: Your push would publish a private email address.

    使用命令:git push -u origin master   ,把本地库的内容推送到远程库的过程中,出现了问题 ——remote: error: GH007: Your push would pu ...

  3. unable to auto-detect email address

    git错误:unable to auto-detect email address 2017年11月14日 08:51:08 陈君豪 阅读数:7914   idea 用git更新的时候报错,详细错误信 ...

  4. git中报unable to auto-detect email address 错误的解决拌办法

    昨天刚配置好的git,今天刚要commit一些修改,就遇到了这个问题** Please tell me who you are. Run git config --global user.email ...

  5. How to Verify Email Address

    http://www.ruanyifeng.com/blog/2017/06/smtp-protocol.html  如何验证 Email 地址:SMTP 协议入门教程 https://en.wiki ...

  6. fatal: unable to auto-detect email address (got 'tim@newton.(none)')的解决方法

    问题描述: 使用git commit -m "wrote a readme file",就遇到了这个问题** Please tell me who you are. Run git ...

  7. git中报unable to auto-detect email address

    git commit 时报错: ** Please tell me who you are. Run git config --global user.email "you@example. ...

  8. fatal: unable to auto-detect email address (got 'CC@LAPTOP-UPQ1N1VQ.(none)')

    git 提交问题出现小解决: 在输入 git commit -m "输入的是对这个版本的描述信息" 然后报错:fatal: unable to auto-detect email ...

  9. How to change default root@ email address linux / postfix / centos?

    Change root@hostname to different email address By default, any email sent by system is sent to root ...

随机推荐

  1. 5、使用ZSetOperations(有序)操作redis(Zset有序集合)

    文章来源:https://www.cnblogs.com/shiguotao-com/p/10564454.html 方法 c参数 s说明   void set(K key, V value); ke ...

  2. 洛谷 P3711 - 仓鼠的数学题(多项式)

    洛谷题面传送门 提供一种不太一样的做法. 假设要求的多项式为 \(f(x)\).我们考察 \(f(x)-f(x-1)\),不难发现其等于 \(\sum\limits_{i=0}^na_ix^i\) 考 ...

  3. Go语言核心36讲(Go语言实战与应用二十)--学习笔记

    42 | bufio包中的数据类型 (上) 今天,我们来讲另一个与 I/O 操作强相关的代码包bufio.bufio是"buffered I/O"的缩写.顾名思义,这个代码包中的程 ...

  4. [linux] 大批量删除任务

    一不小心投了巨多任务,或者投递的资源不合理时,想批量杀掉这些任务. kill的方法就不说了,我这里用qdel的方法. 用了这么一条命令: qstat |sed '1,2d' |awk -F' ' '{ ...

  5. MYSQL5.8-----3

    666666666666666666666666 如多带有通配符的,要使用一下格式 select * from user where usename like "%1\%" ESC ...

  6. kubernetes部署 flannel网络组件

    创建 flannel 证书和私钥flannel 从 etcd 集群存取网段分配信息,而 etcd 集群启用了双向 x509 证书认证,所以需要为 flanneld 生成证书和私钥. cat > ...

  7. Tikz绘制形似万花尺的图片

    初中时意外发现数学课本上有这么一个好玩的图 大概就是把两条相等线段A.B分为10个小段并在点上标序号,A线段1点连B线段9点,2点连8点,依次类推. 假设有这么一个框架图 按照第一张图的方式进一步绘图 ...

  8. MapReduce04 框架原理Shuffle

    目录 2 MapReduce工作流程 3 Shuffle机制(重点) 3.1 Shuffle机制 3.2 Partition分区 默认Partitioner分区 自定义Partitioner分区 自定 ...

  9. 1005.K次取反后最大化的数组和

    1005.K次取反后最大化的数组和 目录 1005.K次取反后最大化的数组和 题目 题解 排序+维护最小值min 题目 给定一个整数数组 A,我们只能用以下方法修改该数组:我们选择某个索引 i 并将 ...

  10. LeetCode移除元素

    LeetCode 移除元素 题目描述 给你一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,并返回移除后数组的新长度. 不需要使用额外的数组空间,你必须仅使用 O(1) ...