AtCoder Grand Contest 6
A - Prefix and Suffix
题意:输入一个整形变量n和两个字符串s,t,使用一些规则求满足条件的最短字符串的长度;规则如下:这个最短字符串的长度不能小于n;它的前n个字符必须与s相同;它的后n个字符必须与t相同
分析:根据题意和样例可知,当s和t相等(长度、字符都相同)时,结果就是n;否则,将t与s逐个字符相比较,如果tj与si相等时,i加1,j加1,num(相等的数量);如果不相等,i加1.
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn = ;
char s[maxn], t[maxn]; int main()
{
int n;
int num;
while(scanf("%d", &n)==&&n)
{
scanf("%s", s);
scanf("%s", t);
if(strcmp(s,t) == )
printf("%d\n", n);
else
{
int i, j;
int len1 = strlen(s);
int len2 = strlen(t);
num = ;
for(i = , j = ; i < len1&&j < len2; )
{
if(s[i] == t[j])
{
num++;
i++;
j++;
}
else
{
i++;
}
}
printf("%d\n", *n-num);
}
}
return ;
}
AtCoder Grand Contest 6的更多相关文章
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
- AtCoder Grand Contest 005
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...
- AtCoder Grand Contest 004
AtCoder Grand Contest 004 A - Divide a Cuboid 翻译 给定一个\(A*B*C\)的立方体,现在要把它分成两个立方体,求出他们的最小体积差. 题解 如果有一条 ...
随机推荐
- 谷歌input框黄色背景问题
input:-webkit-autofill,input:-webkit-autofill:hover,input:-webkit-autofill:focus,input:-webkit-autof ...
- 【转】linux下安装ssh服务器端及ssh的安全配置
一.在服务器上安装ssh的服务器端. $ sudo apt-get install openssh-server 2. 启动ssh-server. $ /etc/init.d/sshrestart 3 ...
- js 时间格式化 代码
Date.prototype.Format = function (fmt) { //author: meizz var o = { &quo ...
- JavaScript中的编码函数
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
- js加密解密
<script> document.write("<xmp>"); document.write(function(p,a,c,k,e,r){}(''.sp ...
- MySQL 语句使用到的关键字 函数 记录
一 处理重复数据 1 使用 UNIQUE 唯一键 (添加数据) 创建表的时候设置 2 使用 DISTINCT (查询数据--过滤) eg:SELECT DISTINCT `name` from ...
- 后台接收URL地址的参数
其实很简单,只是写一下加强记忆 后台接收URL传递过来的参数有两种方法: 第一种用request接收 HttpServletRequest request = ServletActionContext ...
- VB发送后台按键和组合键
http://files.cnblogs.com/files/liuzhaoyzz/VB%E5%8F%91%E9%80%81%E5%90%8E%E5%8F%B0%E7%BB%84%E5%90%88%E ...
- 【Mxnet】----1、使用mxnet训练mnist数据集
使用自己准备的mnist数据集,将0-9的bmp图像分别放到0-9文件夹下,然后用mxnet训练. 1.制作rec数据集 (1).制作list
- centos下安装yaf框架
安装好php环境之后 安装扩展包 $yum install php-devel /usr/bin/ 就会出现phpize工具包 下载yaf-2.2.8.gz源文件,解压后,进入源文件 phpize [ ...