日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

XidianOJ 1037 倍流畅序列

發布時間:2025/3/14 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 XidianOJ 1037 倍流畅序列 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

對于一個0、1串s, 從左端開始讀取它的0獲得序列s0,從右端開始讀取它的1獲得s1,如果s1與s2同構,則稱s為倍流暢序列.
例如:
011001是一個倍流暢序列, 因為:
s0 = 0__00_
s1 = 1__11_

而101不是, 因為:
s0 = _0_
s1 = 1_1

下面的問題是:對于一個0、1串s, 在s后添加最少數目的0或1,使它成為一個倍流暢序列。

輸入

有多組輸入數據,第一行為一個數字T,代表有T組輸入數據 (0<T<=100)。
接下來為T組數據,每組數據占一行,包含一個長度不超過50的0、1串。

輸出

一共T行。
對于每組數據,在一行上輸出添加了最少數目的0或1后所得到的倍流暢序列。

--正文 字符串的長度為len 直接遍歷當前字符串滿不滿足,不滿足就加一位(最多也就是len個) #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std;char str[1000];int main(){int time,T; scanf("%d",&T);for (time=1;time<=T;time++){scanf("%s",str);int now = 0,len = strlen(str);int delta = 0;bool ok = false;while (!ok){if (delta == len) break;while ( now+delta <= len-1-now) {//printf("%d %d\n",now+delta,len-1-now);if ((str[now+delta] - '0') ^ (str[len-1-now] - '0') == 1) {now ++;}else {now = 0; delta ++; break;}}if (now != 0) ok = true; }//printf("%d\n",delta);printf("%s",str);int i;for (i=1;i<=delta;i++){char ch = (str[delta-i] - '0') ^ 1;//printf("%c %c\n",str[delta-i],ch+'0');printf("%c",ch+'0');}printf("\n");}return 0; }

?

轉載于:https://www.cnblogs.com/ToTOrz/p/6137813.html

總結

以上是生活随笔為你收集整理的XidianOJ 1037 倍流畅序列的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。