日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ZOJ-2571 Big String Outspread 模拟

發(fā)布時(shí)間:2025/6/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ZOJ-2571 Big String Outspread 模拟 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題意:給定一個(gè)字符串,按照要求輸出來(lái)。

解法:每次進(jìn)行一次首字母判定,然后根據(jù)不同的情況進(jìn)行遞歸。

代碼如下:

#include <cstdlib> #include <cstdio> #include <cstring> #include <string> #include <iostream> #include <algorithm> using namespace std;char str[300];string display(int ti, int sta, int fuck) {string ret;if (sta > fuck) return ret;if (sta == fuck && !isalpha(str[sta])) return ret;string tmp;if (!isalpha(str[sta])) { // 如果不是以字符開(kāi)始if (isdigit(str[sta])) {int t = 0, i, j;for (i = sta; isdigit(str[i]); ++i) { // 如果是數(shù)字的話 t = t * 10 + (str[i] - '0'); // 得出循環(huán)的次數(shù)數(shù)字 }if (str[i] != '(') { // 如果后面不是括號(hào),那么只有一位 tmp = display(t, i, i) + display(1, i+1, fuck);} else {int cnt = 0;for (j = sta; ; ++j) { // 找到括號(hào)在的位置 if (str[j] == ')') {--cnt;if (!cnt) break;}else if (str[j] == '(') ++cnt;}tmp = display(t, i+1, j-1) + display(1, j+1, fuck);}}else { // 如果是括號(hào)進(jìn)入 int cnt = 0, j;for (j = sta; ; ++j) {if (str[j] == ')') {--cnt;if (!cnt) break; }else if (str[j] == '(') ++cnt;}tmp = display(1, sta, j-1) + display(1, j+1, fuck);}while (ti--) {ret += tmp;}} else {tmp = str[sta] + display(1, sta+1, fuck);while (ti--)ret += tmp; // 把后面的這一個(gè)字母進(jìn)行重復(fù) }return ret; }int main() {int T, len;scanf("%d", &T);while (T--) {scanf("%s", str);len = strlen(str);cout << display(1, 0, len-1) << endl;}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的ZOJ-2571 Big String Outspread 模拟的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。