I. Characters with Hash

Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encrypted value. For instance, he calls Kimura KMR, and calls Suzuki YJSNPI. One day he read a book about SHA-256256 , which can transit a string into just 256256 bits. Mur thought that is really cool, and he came up with a new algorithm to do the similar work. The algorithm works this way: first we choose a single letter L as the seed, and for the input(you can regard the input as a string ss, s[i]s[i] represents the iith character in the string) we calculates the value(|(int) L - s[i]|∣(int)L−s[i]∣), and write down the number(keeping leading zero. The length of each answer equals to 22 because the string only contains letters and numbers). Numbers writes from left to right, finally transfer all digits into a single integer(without leading zero(ss)). For instance, if we choose 'z' as the seed, the string "oMl" becomes "1111 4545 1414".

It's easy to find out that the algorithm cannot transfer any input string into the same length. Though in despair, Mur still wants to know the length of the answer the algorithm produces. Due to the silliness of Mur, he can even not figure out this, so you are assigned with the work to calculate the answer.

Input

First line a integer TT , the number of test cases (T \le 10)(T≤10).

For each test case:

First line contains a integer NN and a character zz, (N \le 1000000)(N≤1000000).

Second line contains a string with length NN . Problem makes sure that all characters referred in the problem are only letters.

Output

A single number which gives the answer.

样例输入 复制
2
3 z
oMl
6 Y
YJSNPI
样例输出 复制
6
10

 #include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define wzf ((1 + sqrt(5.0)) / 2.0)
#define INF 0x3f3f3f3f
#define LL long long
using namespace std; const int MAXN = 1e6 + ; int t, N;
char z;
char temp[MAXN]; int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%d", &t);
while (t --)
{
int i;
scanf("%d %c", &N, &z);
scanf("%s", &temp);
bool first = false;
for (i = ; i < N; ++ i)
{
if (z == temp[i]) continue;
int tt = abs(int(z - temp[i]));
if (tt <= )
first = true;
break;
} if (!first && i == N)
{
printf("1\n");
continue;
} if (first)
printf("%d\n", ((N - i) << ) - );
else
printf("%d\n", (N - i) << );
}
return ;
}

最新文章

  1. Fiddler学习笔记
  2. 团队作业week9 scenario testing
  3. RWD Table Patterns – 响应式表格解决方案
  4. win7开启休眠功能
  5. Sql Server 2008完全卸载方法(其他版本类似)
  6. 爬虫再探实战(五)———爬取APP数据——超级课程表【四】——情感分析
  7. oracle表中某个字段含有字符回车、空格的手动修改方式
  8. Strom的安装及使用
  9. Git 个人/团队项目的创建(一步一图)
  10. ofbiz学习笔记
  11. [置顶] quartznet任务调度和消息调度(JAVA与C#版对比)
  12. linux文件和目录权限
  13. mybatis if-else(写法)
  14. 解决jquery.zclip.js插件无法复制的问题
  15. -eq、-ne、-gt、-ge、-lt、-le英文意思
  16. KASAN实现原理【转】
  17. thinkphp5 or
  18. .NET自动化测试工具链:Selenium+NUnit+ExtentReport
  19. HDU 6191 Query on A Tree(可持久化Trie)
  20. java十年技术栈[总结复习用]

热门文章

  1. luogu P3936 Coloring
  2. MyBatis 开发手册
  3. C# Halcon联合编程问题(二)
  4. windows下cmd组合命令和管道命令
  5. 图论-最小生成树&lt;Kruskal&gt;
  6. OpenGL glMatrixMode() 函数解释与例子
  7. 使用webpack命令打包时,报错TypeError: Cannot read property &#39;presetToOptions&#39; of undefined的解决办法
  8. JVM(8) 线程安全与锁优化
  9. 关于explorer.exe文件或目录已损坏的问题
  10. 学 Python (Learn Python The Hard Way)