A.Poster
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char s[110];
int main()
{
int n,k;
scanf ("%d%d",&n,&k);
scanf ("%s",s);
int len = strlen (s);
if (k > n / 2)
{
while (k < n)
{
printf ("RIGHT\n");
k++;
}
k--;
while (k != 0)
{
printf ("PRINT %c\n",s[k]);
printf ("LEFT\n");
k--;
}
printf ("PRINT %c\n",s[k]);
}
else
{
while (k > 1)
{
printf ("LEFT\n");
k--;
}
k--;
while (k != n - 1)
{
printf ("PRINT %c\n",s[k]);
printf ("RIGHT\n");
k++;
}
printf ("PRINT %c\n",s[k]);
}
return 0;
}
B. Network Configuration
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int num[1000];
int qp(int *left,int *right)
{
int *l,*r;
int k;
if (left >= right)
return 0;
l = left;
r = right;
k = *left;
while (l < r)
{
while (*r <= k && r > l)
r--;
*l = *r;
while (*l >= k && l < r)
l++;
*r = *l;
}
*r = k;
qp(left,r - 1);
qp(l + 1,right);
}
int main()
{
int n,k;
scanf ("%d%d",&n,&k);
for (int i = 0;i < n;i++)
scanf ("%d",&num[i]);
qp(num,&num[n - 1]);
printf ("%d\n",num[k - 1]);
return 0;
}
C. Pattern
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char s1[100001],s2[100001];
int bj[100001] = {0};
int main()
{
int n;
scanf ("%d",&n);
scanf ("%s",s1);
char *p1,*p2;
int *p3;
while (--n)
{
scanf ("%s",s2);
p1 = s1;
p2 = s2;
p3 = bj;
while (*p1 != '\0')
{
if (*p1 == '?')
{
if (*p2 != '?' && *p3 == 0)
{
*p1 = *p2;
}
}else
{
if (*p2 != '?' && *p1 != *p2)
{
*p1 = '?';
*p3 = 1;
}
}
p1++;
p2++;
p3++;
}
}
p1 = s1;
p3 = bj;
while (*p1 != '\0')
{
if (*p1 == '?' && *p3 == 0)
*p1 = 'a';
p1++;
p3++;
}
printf ("%s\n",s1);
return 0;
}
碰巧前三个都是模拟题。