题目链接:http://codeforces.com/problemset/problem/448/B

题目意思:给出两种操作automaton:可以删除字符串中任意一个字符; array:交换字符串中任意两位。运用这两种操作的次数不限定,问如何运用这两种操作(或其中一种,或两种结合都不能够)使得字符串 s 转换成字符串 t

昨晚做的时候,顶住疲倦死撑,过不了pretest 5,我以为是因为这组数据:ttauotdf  auto,当时没想到怎么做,太困了......今日做才发现原来要用到两个指针!而且我发现好多AC代码根本过不了这组数据,她们输出的竟然是 automaton!!!幸好作者还是起到模范作用滴^_^

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
char s[maxn], t[maxn];
int cnt[maxn]; void solve()
{
int ls = strlen(s);
int lt = strlen(t);
memset(cnt, , sizeof(cnt));
for (int i = ; i < ls; i++)
cnt[s[i]-'a']++;
for (int i = ; i < lt; i++)
cnt[t[i]-'a']--;
int aut, arr, both;
aut = arr = both = ;
for (int i = , j = ; i < ls; i++)
{
if (s[i] == t[j])
j++;
if (j == lt)
{
aut ^= ;
break;
}
}
for (int i = ; i < ; i++)
{
arr &= (cnt[i] == );
both &= (cnt[i] >= ); // 这个“=”很重要,因为有可能s中有的字母t没有!
}
if (!aut)
printf("automaton\n");
else if (arr)
printf("array\n");
else if (both)
printf("both\n");
else
printf("need tree\n");
} int main()
{
while (scanf("%s%s", s, t) != EOF)
{
solve();
}
return ;
}

最新文章

  1. CentOS下解压缩命令
  2. 【bzoj2333】 [SCOI2011]棘手的操作 可并堆+lazy标记
  3. Windows命令行重命名文件
  4. iOS开发UI篇—实现一个私人通讯录小应用【转】
  5. HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
  6. A Full Hardware Guide to Deep Learning
  7. jsp连接MySQL操作GIS地图数据,实现添加point的功能
  8. 【转】C/C++程序员应聘常见面试题深入剖析
  9. HTML5小游戏《智力大拼图》发布,挑战你的思维风暴
  10. Leetcode 197. Rising Temperature
  11. [Leetcode] Binary tree level order traversal二叉树层次遍历
  12. android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
  13. Django03-视图系统views
  14. golang使用chrome headless获取网页内容
  15. C++重载操作符自增自减
  16. postgresql-分页重复数据探索
  17. 查看电脑保存的wifi密码
  18. Prism中命令可用性无法自动刷新
  19. 【CF553E】Kyoya and Train 最短路+cdq分治+FFT
  20. 有关C#中List排序的总结

热门文章

  1. 在GridView中的每一页末尾添加空行
  2. CodeForces 379D 暴力 枚举
  3. Day 2 操作系统基础
  4. HUNAN 11562 The Triangle Division of the Convex Polygon(大卡特兰数)
  5. VMware View 要求操作句柄的状态错误
  6. htmlcxx取指定字段实例
  7. 还在为不停build 烦恼么?看这里~~
  8. 图片异步载入之 Android-Universal-Image-Loader
  9. 步步为营(十六)搜索(二)BFS 广度优先搜索
  10. 2014牡丹江 现场赛 F zoj 3824 Fiber-optic Network