记录洛谷刷题QAQ,一些不太优雅的代码
一、[COCI2006-2007#1] Okviri
题面翻译
“彼得·潘框架”是一种装饰文字,每一个字母都是由一个菱形框架。一个彼得·潘框架看起来像这样 (x是字母,#是框架):
..#..
.#.#.
#.X.#
.#.#.
..#..
然而,只是一个框架会有些沉闷,所以我们每遇到三个字母会把第三个字母用温迪框架把它框起来。温迪框架看起来像这样:
..*..
.*.*.
*.X.*
.*.*.
..*..
当温迪和彼得·潘的框架重叠时,温迪框架覆盖在上面。 (见样例3和4)
输入格式: 一行包含至多15个英文字母的大写字母。
输出格式: 输出使用彼得·潘和温迪框架写成的5行文字。
题目描述
“Peter Pan frames” are a way of decorating text in which every character is framed by a diamond shaped frame, with frames of neigbhouring characters interleaving. A Peter Pan frame for one letter looks like this (‘X’ is the letter we are framing):
..#..
.#.#.
#.X.#
.#.#.
..#..
However, such a framing would be somewhat dull so we’ll frame every third letter using a “Wendyframe”. A Wendy frame looks like this:
..*..
.*.*.
*.X.*
.*.*.
..*..
When a Wendy frame interleaves with a Peter Pan frame, the Wendy frame (being much nicer) is put on top. For an example of the interleaving check the sample cases.
输入格式
The first and only line of input will contain at most 15 capital letters of the English alphabet.
输出格式
Output the word written using Peter Pan and Wendy frames on 5 lines.
样例 #1
样例输入 #1
A
样例输出 #1
..#..
.#.#.
#.A.#
.#.#.
..#..
样例 #2
样例输入 #2
DOG
样例输出 #2
..#...#...*..
.#.#.#.#.*.*.
#.D.#.O.*.G.*
.#.#.#.#.*.*.
..#...#...*..
样例 #3
样例输入 #3
ABCD
样例输出 #3
..#...#...*...#..
.#.#.#.#.*.*.#.#.
#.A.#.B.*.C.*.D.#
.#.#.#.#.*.*.#.#.
..#...#...*...#..
代码如下:
//一道很烦的题
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
char ans[10][100];
int main(){
char a[16];
scanf("%s",&a);
for(int i=1;i<=5;++i){
int sum1=3,sum2=2,sum3=1;
if(i==1||i==5){
while(sum1+4<=99){
ans[i][sum1]='#',sum1+=4;
}
}
if(i==2||i==4){
while(sum2+2<=99){
ans[i][sum2]='#',sum2+=2;
}
}
if(i==3){
while(sum3+4<=99){
ans[i][sum3]='#',sum3+=4;
}
}
}
int na=strlen(a);
int f1=3;
for(int i=0;i<na;++i){
ans[3][f1]=a[i];
f1+=4;
}
f1-=2;
int qaq=11;
while(qaq<f1){
for(int i=1;i<=5;++i){
if(i==1||i==5){
ans[i][qaq]='*';
}
if(i==2||i==4){
ans[i][qaq+1]='*';
ans[i][qaq-1]='*';
}
if(i==3){
ans[i][qaq-2]='*';
ans[i][qaq+2]='*';
}
}
qaq+=12;
}
for(int i=1;i<=5;++i){
for(int j=1;j<=f1;++j){
if((ans[i][j]!='*'&&ans[i][j]!='#')&&(ans[i][j]<'A'||ans[i][j]>'Z')){
printf(".");
}else printf("%c",ans[i][j]);
}
printf("\n");
}
return 0;
}
二、[COCI2006-2007#2] R2
题面翻译
设S=(R1+R2)/2,给定R1与S ( − 1000 < = R 1 , S < = 1000 ) (-1000<=R1,S<=1000) (−1000<=R1,S<=1000),求R2。
感谢@Xeonacid 提供的翻译
题目描述
The number S is called the mean of two numbers R1 and R2 if S is equal to (R1+R2)/2. Mirko’s birthday present for Slavko was two integers R1 and R2. Slavko promptly calculated their mean which also happened to be an integer but then lost R2! Help Slavko restore R2.
输入格式
The first and only line of input contains two integers R1 and S, both between -1000 and 1000.
输出格式
Output R2 on a single line.
样例 #1
样例输入 #1
11 15
样例输出 #1
19
样例 #2
样例输入 #2
4 3
样例输出 #2
2
代码如下:
//一道简单的题
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
long long one , ans;
scanf("%lld%lld",&one,&ans);
long long two = 2.0*ans - one;
printf("%lld\n",two);
return 0;
}
三、[COCI2006-2007#2] ABC
题面翻译
【题目描述】
三个整数分别为 A , B , C A,B,C A,B,C。这三个数字不会按照这样的顺序给你,但它们始终满足条件: A < B < C A < B < C A<B<C。为了看起来更加简洁明了,我们希望你可以按照给定的顺序重新排列它们。
【输入格式】
第一行包含三个正整数 A , B , C A,B,C A,B,C,不一定是按这个顺序。这三个数字都小于或等于 100 100 100。第二行包含三个大写字母 A A A、 B B B 和 C C C(它们之间没有空格)表示所需的顺序。
【输出格式】
在一行中输出
A
A
A,
B
B
B 和
C
C
C,用一个
(空格)隔开。
感谢 @smartzzh 提供的翻译
题目描述
You will be given three integers A, B and C. The numbers will not be given in that exact order, but we do know that A is less than B and B less than C.
In order to make for a more pleasant viewing, we want to rearrange them in the given order.
输入格式
The first line contains three positive integers A, B and C, not necessarily in that order. All three numbers will be less than or equal to 100.
The second line contains three uppercase letters ‘A’, ‘B’ and ‘C’ (with no spaces between them) representing the desired order.
输出格式
Output the A, B and C in the desired order on a single line, separated by single spaces.
样例 #1
样例输入 #1
1 5 3
ABC
样例输出 #1
1 3 5
样例 #2
样例输入 #2
6 4 2
CAB
样例输出 #2
6 2 4
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int small(int a, int b,int c){
int point = a;
if(b < point)
point = b;
if(c < point)
point = c;
return point;
}
int big(int a, int b,int c){
int point = a;
if(b > point)
point = b;
if(c > point)
point = c;
return point;
}
int main(int argc, char *argv[]) {
int A, B, C ;
int a, b, c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF){
A = small(a,b,c);
C = big(a,b,c);
B = a+b+c-A-C;
//printf("%d %d %d\n",A,B,C);
char num[4];
scanf("%s",&num);
int len = strlen(num);
for(int i = 0;i < len;i++){
if(num[i] == 'A')
printf("%d ",A);
if(num[i] == 'B')
printf("%d ",B);
if(num[i] == 'C')
printf("%d ",C);
}
printf("\n");
}
return 0;
}
四、[COCI2017-2018#3] Aron
题面翻译
Aron给他的朋友们买礼物后在礼物店排队,它的前面有n个人,但是它发现有些人实在等待他的朋友而并非在排队买单,并且我们可以认为站在一个人后面的朋友都穿着匹配颜色的衬衫,而两个相邻的群体、相邻的个人或相邻的个人和一个集体将永远不会穿着相同颜色的衬衫。
编写一个程序,给定排队的人所穿的衣服的颜色,输出Aron在第多少位?
题目描述
The holiday season is near! Aron wants to get gifts for his friends in Zagreb, so in order to get them on time, he visited a famous toy store in London. After picking out the gifts, he went to the register and discovered that there were already N people in line. Luckily, he noticed that there were groups of people standing in line, in addition to individual customers. A group of people consists of a customer and their friends waiting for them to complete the purchase.
The moment when the customer is done, they and their friends leave the line.
The people considered a group are standing one behind the other and are wearing shirts of matching colour. Two adjacent groups, adjacent individuals or adjacent individual and a group, will never be wearing shirts of the same colour.
Write a program that will, given the data on the people standing in line, output which person in line Aron is.
输入格式
The first line of input contains the positive integer N (1 ≤ N ≤ 25) from the task.
Each of the following N lines contains a single character, an uppercase letter of the English alphabet that represents the shirt colour of the
i
t
h
i^{th}
ith person in line.
输出格式
You must output the required number from the task.
样例 #1
样例输入 #1
3
C
Z
P
样例输出 #1
4
样例 #2
样例输入 #2
6
C
C
P
C
Z
Z
样例输出 #2
5
样例 #3
样例输入 #3
6
B
B
B
B
B
B
样例输出 #3
2
提示
Clarification of the second test case:
First in line is the group consisting of two people in red shirts. Second in line is an individual in the blue shirt, third in line is an individual in the red shirt, and fourth in line is a group in green shirts. This makes Aron fifth in line.
代码如下:
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
int n;//前面有n个人
scanf("%d",&n);
char num[n];
for(int i = 0; i < n;i++)
{
scanf("%s",&num[i]);
}
int sum = n;
for(int i = 0;i < n-1;i++)
{
if(num[i] == num[i+1])
{
sum--;
}
}
printf("%d\n",sum+1);
return 0;
}
五、[AHOI2018初中组]报名签到
题目描述
n n n 位同学(编号从 1 1 1 到 n n n)同时来到体育馆报名签到,领取准考证和参赛资料。为了有序报名,这 n n n 位同学需要按编号次序(编号为 1 1 1 的同学站在最前面)从前往后排成一条直线。然而每一位同学都不喜欢拥挤,对于第 i i i 位同学,如果有另外一位同学距离他/她的距离小于 a i a_i ai,那么就会发生冲突。小可可想知道如果要不发生任何冲突的情况下,这 n n n 位同学排队的队列最短长度是多少。
输入格式
第一行一个整数 n n n ,表示报名签到的同学人数。
第二行有 n n n 个整数,第 i i i 个整数 a i a_i ai 表示第 i i i 个同学必须与其他同学保持的距离。
输出格式
输出一行,包括一个整数,表示这 n n n 位同学排队队列的最小长度。
注意: n n n 位同学要按 1 1 1 到 n n n 的次序从前往后排队。
样例 #1
样例输入 #1
3
3 1 2
样例输出 #1
5
提示
对于 20 % 20\% 20% 的数据满足: 1 ≤ n ≤ 20 1\le n\le 20 1≤n≤20。
对于 70 % 70\% 70% 的数据满足: 1 ≤ n ≤ 1 0 4 1\le n\le 10^4 1≤n≤104。
对于 100 % 100\% 100% 的数据满足: 1 ≤ n ≤ 1 0 5 1\le n\le 10^5 1≤n≤105, 1 ≤ a i ≤ 1 0 5 1\le a_i\le 10^5 1≤ai≤105。
代码如下:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//找到最小值
int small(int a, int b){
int point = a;
if(a <= b){
point = b;
}
return point;
}
int main(int argc, char *argv[]) {
long long n;
scanf("%d",&n);
long long i;
long long sum = 0;
int NUM[n];
for(i = 0;i < n;i++){
scanf("%d",&NUM[i]);
}
long long point;
for(i = 0;i < n-1;i++){
point = small(NUM[i],NUM[i+1]);
sum = point +sum;
}
printf("%lld\n",sum);
return 0;
}