diff --git a/TangDou/LuoGuBook/TestA.cpp b/TangDou/LuoGuBook/TestA.cpp index f005bb6..be1b64d 100644 --- a/TangDou/LuoGuBook/TestA.cpp +++ b/TangDou/LuoGuBook/TestA.cpp @@ -1,46 +1,32 @@ #include - using namespace std; -const int INF = 0x3f3f3f3f; -typedef long long LL; -const int N = 10; -char g[N][N]; -int dx[] = {-1, 0, 1, 0}; //上右下左 -int dy[] = {0, 1, 0, -1}; //上右下左 +const int N = 210; +int p[N]; +char s[N], t[N]; int main() { - int x1, y1, x2, y2; - for (int i = 0; i < 10; i++) - for (int j = 0; j < 10; j++) { - cin >> g[i][j]; - if (g[i][j] == 'C') x1 = i, y1 = j; - if (g[i][j] == 'F') x2 = i, y2 = j; - } - int cd = 0, fd = 0; - int cnt = 0; + int n; + cin >> n; + for (int i = 0; i < n; i++) { + int x; + cin >> x; // 输入的是 4 1 2 3 ,映射成: 3 0 1 2,改成下标从0开始,方便后续计算 + p[i] = x - 1; + } while (true) { - int tx = x1 + dx[cd], ty = y1 + dy[cd]; - if (tx >= 10 || tx < 0 || ty >= 10 - || ty < 0 || g[tx][ty] == '*') - cd = (cd + 1) % 4; - else - x1 = tx, y1 = ty; - tx = x2 + dx[fd], ty = y2 + dy[fd]; - if (tx >= 10 || tx < 0 || ty >= 10 - || ty < 0 || g[tx][ty] == '*') - fd = (fd + 1) % 4; - else - x2 = tx, y2 = ty; - cnt++; - if (x1 == x2 && y1 == y2) { - printf("%d", cnt); - break; - } - if (cnt > 100000) { - printf("0"); - break; + int m; + cin >> m; + if (m == 0) break; + + cin >> s; // cin输入字符数组,与string没什么区别 + // 补空格 + for (int i = strlen(s); i < n; i++) s[i] = ' '; + + for (int i = 1; i <= m; i++) { // 加密m次 + for (int j = 0; j < n; j++) // 每个字符 + t[p[j]] = s[j]; // 替换 + memcpy(s, t, sizeof t); // 还原为s } + cout << s << endl; } - return 0; } \ No newline at end of file diff --git a/TangDou/LuoGuBook/TestA.in b/TangDou/LuoGuBook/TestA.in new file mode 100644 index 0000000..fc46eec --- /dev/null +++ b/TangDou/LuoGuBook/TestA.in @@ -0,0 +1,203 @@ +10 +6 4 2 3 5 10 1 8 9 7 +1 yK +2 dpZ +3 MZPj +4 mPPAF +5 tbTkmO +6 yaLaRwN +7 SstyNhUh +8 doRGbtjMC +9 PAUTmaVMQu +10 o +11 kO +12 xIu +13 BTbL +14 mGqXL +15 BlrimJ +16 JrewTit +17 bwWalTOx +18 wleUJeLHg +19 DdkZEsnuku +20 t +21 kP +22 oyI +23 sWTq +24 yitsK +25 abMttP +26 CxJhncQ +27 vIYBJuUf +28 qAdmzEFBz +29 obbXmqRSPZ +30 p +31 Jt +32 NxQ +33 dnrd +34 dEpDi +35 tqFXkQ +36 FAeivyF +37 MjrVxWTa +38 PBgyAqliK +39 ffASrnfXaL +40 E +41 yd +42 OQi +43 BLgc +44 eWqgg +45 jcBGoq +46 ZNXxsfZ +47 AdHkMFBQ +48 tpmLApodx +49 PjwbCPDUzl +50 A +51 NB +52 uOF +53 uOXN +54 hOyUb +55 nniezg +56 qUIpbDU +57 rVsineZx +58 mxElGHNeY +59 BVmwNPbXPH +60 T +61 sx +62 Wku +63 kGxY +64 yJDms +65 cfciag +66 MnQhZVk +67 UnYQIVUD +68 fAgWtYESQ +69 bVvjsOuOtt +70 w +71 pT +72 GNd +73 Aodk +74 nukUA +75 zHtkZE +76 sxfVVcg +77 pxVzSRxA +78 WBpEsfYNO +79 nHrLCxprLO +80 i +81 Kn +82 WRe +83 IrND +84 UUWle +85 vYKOBC +86 hkLYkze +87 wZGkMJIR +88 ZygIIZvlz +89 nuuaTfizfE +90 i +91 XL +92 OqT +93 bMIW +94 hneFX +95 eIhgfM +96 BZOmyeS +97 tsbCzvzb +98 SrAvrAaQZ +99 DntLSCBArV +100 D +101 AS +102 mPM +103 VsWV +104 mYbmY +105 UChWFP +106 KVDdPDO +107 DPmibRQt +108 OTSgeGDSq +109 KImFpswHck +110 n +111 LF +112 pdG +113 RSAk +114 xbnFc +115 zgjbFg +116 dpMJabY +117 tZaXckwp +118 VUxBxTqFF +119 PMJBCwQght +120 N +121 FD +122 lyQ +123 fulx +124 SHddp +125 qBYsJm +126 Iyrvgjx +127 WTSBJYiH +128 NBfKRpxiL +129 SkEdSHJVoB +130 s +131 Rq +132 wld +133 KeWE +134 bHfPG +135 YFEtIV +136 EKSqcLE +137 KXdkZPAR +138 JyvIipCLV +139 bupcFGTZfF +140 F +141 wB +142 VVK +143 YLVX +144 QEQxE +145 SodJFC +146 uMlkTQz +147 YEEZmSmt +148 KOABWvARP +149 ZHupEUaSiS +150 F +151 hU +152 CEB +153 JRBd +154 ClwCt +155 kQNcwX +156 lpoikcq +157 xYMBpnwl +158 TkHzgukDA +159 yDtDUXTdyd +160 j +161 ai +162 Byw +163 pKiE +164 pqrpN +165 erGkyY +166 PUqRMSn +167 jrQJswWT +168 tqPeDSdbh +169 hbKjgODluk +170 t +171 xz +172 vSA +173 NsSb +174 xFBbV +175 dzBFRA +176 YbExZfp +177 noqZbxHg +178 NdIjeOKoX +179 YgmOpEeAUT +180 h +181 uE +182 HIY +183 Hhyi +184 niVbp +185 tJpTTL +186 PtMJkqM +187 NewAnYmW +188 ohqttoYdA +189 ymdYIvgAtP +190 z +191 Xx +192 nzO +193 Oyaw +194 MGKSj +195 Tzoexp +196 tQaaPey +197 ywNszTFr +198 QpSKKeWZq +199 OacGECgaaD +200 A +0 diff --git a/TangDou/LuoGuBook/TestB.cpp b/TangDou/LuoGuBook/TestB.cpp index 1b587f5..7459580 100644 --- a/TangDou/LuoGuBook/TestB.cpp +++ b/TangDou/LuoGuBook/TestB.cpp @@ -1,17 +1,32 @@ #include - using namespace std; +const int N = 110; +int getWuXu(string x){ + int sum = 0; + for (int i = 0; i < x.size(); i++) + for (int j = i + 1; j < x.size();j++) + if (x[i] > x[j]) sum++; + return sum; +} +struct Node{ + int id; + string s; + int wxd; + const bool operator<(const Node &t){ + if (wxd == t.wxd) return id < t.id; + return wxd < t.wxd; + } +} a[N]; int main() { - for (int i = 100; i <= 999; i++) { - int sum = 0; - int n = i; - while (n) { - int x = n % 10; - n /= 10; - sum += x * x * x; - } - if (sum == i) cout << i << " "; + int n, m; + cin >> n >> m; + for (int i = 0; i < m;i++){ + cin >> a[i].s; + a[i].id = i, a[i].wxd = getWuXu(a[i].s); } - return 0; + sort(a, a + m); + for (int i = 0; i < m;i++) + cout << a[i].s << endl; + return 0; } \ No newline at end of file