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的更多相关文章

  1. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  2. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  3. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  4. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  5. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  6. AtCoder Grand Contest 008

    AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...

  7. AtCoder Grand Contest 007

    AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...

  8. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

  9. AtCoder Grand Contest 005

    AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...

  10. AtCoder Grand Contest 004

    AtCoder Grand Contest 004 A - Divide a Cuboid 翻译 给定一个\(A*B*C\)的立方体,现在要把它分成两个立方体,求出他们的最小体积差. 题解 如果有一条 ...

随机推荐

  1. 如何监控checkbox改变

    现在想实现一个效果,即使弹幕开关,弹幕开关实际是checkbox $(document).on('change',"#barrage",function(){ if (!$(thi ...

  2. freeMarker生成静态页面

    项目结构图 footer.ftl des==>${f.des}<br/> <a href="http://www.baidu.com"> 百度 < ...

  3. 转:C/C++程序员简历模板

    https://github.com/geekcompany/ResumeSample/blob/master/c.md 本简历模板由国内首家互联网人才拍卖网站「 JobDeer.com 」提供. ( ...

  4. java内存划分

    运行时数据区域 Java虚拟机在执行Java的过程中会把管理的内存划分为若干个不同的数据区域.这些区域有各自的用途,以及创建和销毁的时间,有的区域随着虚拟机进程的启动而存在,而有的区域则依赖线程的启动 ...

  5. Address already in use: JVM_Bind:8080 的解决办法<转>

    出错情况:运行 Tomcat 时报错 含义:8080 位置显示的端口被其他进程占用 解决方法: 方法1: 开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID ...

  6. webstorm自动编译typescript

    http://bbs.egret.com/thread-1752-1-1.html http://bbs.egret.com/thread-1912-1-1.html

  7. JAVA开发错误总结(仅记录遇到的错误---后续不断更新......)

    =======华丽分割线(工具总结)===================== 1:Maven项目中junit测试找不到主类的问题 Class not found com.test.utils.tes ...

  8. ActiveReports中如何在后台导出运行时绑定数据源报表

    ActiveReports支持运行时绑定数据源功能,这种绑定数据源方法使用较为普及,然而很多系统中都需要在后台导出报表文件,所以用户就很困惑,ActiveReports中如何在后台导出运行时绑定数据源 ...

  9. yii2-basic后台管理功能开发之五:用户权限的控制

    需求:后台有两种权限+管理员+用户 区别:可以访问的页面不同 解决方法:用户表添加role字段,使用到的是yii2 存取控制过滤器(ACF)方法. >1在web.php中配置授权的类,有两种,我 ...

  10. Win10重复按键盘经常按不出?Win10关闭筛选键步骤

    在Win10系统中,有用户发现,有时重复按一个键位,经常会出现打不出字符的情况,导致输入效率降低,其实这很有可能是你开启了筛选键导致,筛选键帮助用户忽略那些短时间的按键动作,下面我们就来看看win10 ...