模拟 Coder-Strike 2014 - Round 1 A. Poster

 

题目地址:http://codeforces.com/problemset/problem/412/A

复制代码
 1 /*
 2     模拟:题目没看懂,但操作很简单,从最近的一头(如果不在一端要先移动到一端)往另一头移动,顺便打印内容
 3 */
 4 #include <cstdio>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <cmath>
 8 #include <cstring>
 9 #include <string>
10 #include <map>
11 using namespace std;
12 
13 const int MAXN = 100 + 10;
14 const int INF = 0x3f3f3f3f;
15 char s[MAXN];
16 
17 int main(void)        //Coder-Strike 2014 - Round 1 A. Poster
18 {
19     //freopen ("E.in", "r", stdin);
20 
21     int n, k;
22     while (~scanf ("%d%d", &n, &k))
23     {
24         scanf ("%s", &s);
25         int pos;    int flag;
26         
27         if (k <= (n) / 2)
28         {
29             pos = k - 1;    flag = 0;
30         }
31         else
32         {
33             pos = n - k;    flag = 1;
34         }
35 
36         while (pos--)    (flag) ? puts ("RIGHT") : puts ("LEFT");
37 
38         if (flag == 1)
39         {
40             for (int i=n-1; i>=0; --i)
41             {
42                 printf ("PRINT ");
43                 printf ("%c\n", s[i]);
44                 if (i > 0)    puts ("LEFT");
45             }
46         }
47         else
48         {
49             for (int i=0; i<n; ++i)
50             {
51                 printf ("PRINT ");
52                 printf ("%c\n", s[i]);
53                 if (i < n - 1)    puts ("RIGHT");
54             }
55         }
56     }
57 
58     return 0;
59 }
复制代码

 

posted @   Running_Time  阅读(131)  评论(0编辑  收藏  举报
编辑推荐:
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
阅读排行:
· JDK 24 发布,新特性解读!
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· Ollama系列05:Ollama API 使用指南
· 为什么AI教师难以实现
点击右上角即可分享
微信分享提示