传送门

Examples
input 1
5
I want to order pizza
output 1
Iwantorderpizza
input 2
5
sample please ease in out
output 2
sampleaseinout

题意:如果前一个单词的后缀和第二个单词的前缀相同,那他们合并的时候省略前缀(看样例)。

题解:我们把前一个的后缀和后一个的前缀进行字符串hash,hash值一样的表示他们后缀和前缀相同可省略,用个pos标记第二个串从哪个位置开始要合并到前一个串上面,hash值相同时更新pos。

  不知道为啥我用char数组写一直tle3,然后改成用string,结果wa1了????显示 “wrong answer Unexpected EOF in the participants output”于是在输入n的时候加了个多组输入终于过了。

代码:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + ;
const ll P = ;
const ll mod = 1e9 + ;
string s,ans;
int main(){
int n;
while(~scanf("%d",&n)){
ans="\0";
while(n--) {
cin>>s;
int ls = s.size(),la = ans.size();
int len = min(la,ls),pos = ;
ll hs = ,ha = ,p = ;
for (int i = ; i < len; i++) {
ha = ((ans[la--i]*p%mod)+ha)%mod;
hs = ((hs*P%mod)+s[i])%mod;
if (ha == hs) pos = i+;
p=p*P%mod;
}
ans+=s.substr(pos);
}
cout<<ans<<"\n";
}
return ;
}

最新文章

  1. 通过arcgis在PostgreSQL中创建企业级地理数据库
  2. Django进阶2
  3. SGU 495. Kids and Prizes
  4. java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
  5. 实验5 简单嵌入式WEB服务器实验 实验报告 20135303 20135326
  6. POJ 2429 GCD &amp; LCM Inverse (Pollard rho整数分解+dfs枚举)
  7. 元组的cmp()内建函数
  8. Customer reviews on Lexia3 V48 diagnostic tool in EOBD2.FR
  9. excel 导入功能
  10. 【原】Windows中使用Redis基本入门教程
  11. GCC优化选项-fomit-frame-pointer对于esp和ebp优化的作用
  12. MYSQL create database 和 create table 做了一些什么!
  13. js获取网页屏幕可见区域高度
  14. http请求的概念
  15. FFT算法的完整DSP实现(转)
  16. 分享一些免费的MD5解密网站
  17. Dojo初探之2:设置dojoConfig详解,dojoConfig参数详解+Dojo中预置自定义AMD模块的四种方式(基于dojo1.11.2)
  18. JSR-303 Bean Validation 介绍及 Spring MVC 服务端参数验证最佳实践
  19. 网络爬虫技术Jsoup——爬到一切你想要的(转)
  20. 理解WebKit和Chromium: Web应用和Web运行环境

热门文章

  1. Python--day26--反射
  2. Vue 获取DOM元素ref
  3. H3C 单区域OSPF配置示例一(续)
  4. P1056 骑士游历
  5. H3C端口状态迁移
  6. js实现new
  7. Python程序执行顺序
  8. Dubbo-本地Bean测试
  9. hadoop fs、hadoop dfs与hdfs dfs命令的区别
  10. Python_自定义关键字的使用