ACM-ICPC 2018 徐州賽區網路預賽 I. Characters with Hash【簽到題】
- 1000ms
- 262144K
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-256 , which can transit a string into just 256 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 s, s[i] represents the iith character in the string) we calculates the value(∣(int)L−s[i]∣), and write down the number(keeping leading zero. The length of each answer equals to 2 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(s)). For instance, if we choose 'z' as the seed, the string "oMl" becomes "11 45 14".
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 T , the number of test cases T (T≤10).
For each test case:
First line contains a integer N and a character z, N (N≤1000000).
Second line contains a string with length N . 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
題目來源
題目大意:T組測試,每組給出整數n和字母L,以及一個長度為n的字串S(只含字母),字母L減去S的每一個字元後取絕對值,結果不足2位的補前導零,然後拼湊成一個字串,問這個此字串去掉前導零後的長度。比如L='z' ,S='oMl',那麼拼湊的字串為“11 45 14”,長度為6
題解:由於不夠兩位的要補前導零,因此實際長度就為2*n,但是這是沒有去除前導零的長度,正確答案是要去掉前導零,只要去掉前導零即可,但是要注意當結果全是0時,去掉前導零後就保留一個0,因此答案為1
AC的C++程式碼:
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
int t,length,ans;
char c;
string s;
scanf("%d",&t);
while(t--){
scanf("%d %c",&length,&c);
ans=length*2;
cin>>s ;
for(int i=0;i<length;i++){
int temp=abs(c-s[i]);
if(!temp) ans-=2;//如果是前導零 就要減去2個0
else{
if(temp<10)//如果第一個非零的數小於10就要去掉1個前導0
ans-=1;
break;
}
}
if(ans==0)//當結果全是0時,去掉前導零後就保留一個0,因此答案為1
ans=1;
cout << ans <<endl;
}
return 0;
}
相關文章
- ACM-ICPC 2018 徐州賽區網路預賽ACM
- ACM-ICPC 2018 徐州賽區網路預賽 F. Features TrackACM
- ACM-ICPC 2018 瀋陽賽區網路預賽ACM
- 2018 徐州網路賽 G 題解
- ACM-ICPC 2018 南京賽區網路預賽__B The writing on the wall【列舉】ACM
- ACM-ICPC 2018 南京賽區網路預賽__E AC Challenge【狀態壓縮+DP】ACM
- ACM-ICPC 2018 南京賽區網路預賽__K The Great Nim Game【博弈論+費馬小定理+DP】ACMGAM
- ACM-ICPC 2018 南京賽區網路預賽 __G Lpl and Energy-saving Lamps【線段樹+模擬】ACMLAMP
- ACM-ICPC 2018 南京賽區網路預賽__J. Sum【尤拉篩法+質因子分解+思維】ACM
- ACM-ICPC 2018 南京賽區網路預賽__L. Magical Girl Haze 【Dijkstra演算法+分層圖思想】ACM演算法
- 2018 icpc徐州站網路賽 H Ryuji doesn't want to study
- 2018 瀋陽賽區網路預賽 I.Lattice's basics in digital electronics(模擬)Git
- 第 43 屆 ACM-ICPC 亞洲區域賽(徐州)現場賽名額分配規則及相關說明ACM
- 2018 北京賽區網路預選賽 A. Saving Tang Monk II(BFS+優先佇列)佇列
- ICPC2018徐州網路賽 H.Ryuji doesn't want to study ( 樹狀陣列陣列
- 2018華為網路技術大賽
- 2018 ICPC南京區域賽題解 更新至 8 題
- 2024ccpc網路賽補題
- 2024 ICPC 網路預選賽 第 2 場
- 2018icpc 南京網路賽L Magical Girl Haze
- zoj-4053(2018ICPC青島網路賽K題)啟發式分裂
- 2018王者榮耀KPL秋季賽賽程表 2018王者榮耀KPL秋季賽賽制
- ACM-ICPC 2018 決賽落幕,中國戰隊一金兩銀戰績收官ACM
- 新生賽及預選賽 10
- [題解]NOIP2018模擬賽 plutotree
- 高校戰“疫”網路安全分享賽-部分PWN題-wp
- 2024ICPC網路賽第一場題解(部分)
- 第43屆ACM-ICPC國際大學生程式設計競賽 亞洲區域賽南京站現場賽名額分配相關說明ACM程式設計
- 2024春秋杯網路安全聯賽夏季賽-PWN-Writeup
- 2016中國“網際網路+”創業創新大賽(西北+山西)賽區決賽成功舉辦 優秀專案將會師海口...創業
- 2016中國“網際網路+”創業創新大賽(西北+山西)賽區決賽成功舉辦優秀專案將會師海口創業
- 2024中國工業網際網路安全大賽智慧家電行業賽道選拔賽行業
- “網際網路+”大學生創新創業大賽來了,歡迎報名龍蜥社群賽題!創業
- 2021年春秋杯網路安全聯賽秋季賽 勇者山峰部分wp
- 《阿里雲天池大賽賽題解析》——O2O優惠卷預測阿里
- 新興科技+網際網路創新大賽,科技+社會公益專項賽
- 第八屆“網際網路+”大賽 | 雲原生賽道邀你來挑戰
- 西湖論劍·2022中國杭州網路安全技能大賽線上初賽火熱開賽