2017 天梯赛 部分题解

先放几道我昨天补的,我应该还能做出来两个。。。等有空补完了再加进来吧

ok~ Here we go ~、


L1-1 古风排版(20 分)

中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。

输入格式:

输入在第一行给出一个正整数N<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。

输出格式:

按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)。

输入样例:

4
This is a test case

输出样例:

asa T
st ih
e tsi
 ce s

思路:

首先看起来,挺动态,有点吓人,但是,循环本身就是一个不动态的东西,只能从上到下,从左到右输出,
这就注定输出与某个规律有关,不难看出。这种骚输出,每一排输出的字符,包括空格,都是与它所在的位置,
即角标与输入的n的余数有关。需要注意两点,一个是字符串角标从0开始,另一个更重要,决定你是否会PE,
就是,由于输入字符串带空格,要用gets读入,如果n直接按整型输入,scanf和读入字符串的gets放一起会不匹配。
所以先把n按字符串gets读入,再用atoi()函数转成整型。如果不会用atoi(), 就直接整型读入然后getchar()。
而且由于字符串长度未必能整除n,意味着第一列就会填不满。

要先用空格补齐。 buy the way~第一次用atoi()时我没开多组,换成getchar()就可以开多组了。

本人AC代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
using namespace std;
//char p[3];
char s[1033];
int n;

int main() {
    //gets(p);
    //int n = atoi(p);
    scanf("%d", &n);
    getchar();
    gets(s);
    int l = strlen(s);
    while(l % n != 0) {
        s[l] = ' ';
        l++;
    }
    for(int i = 0; i < n; i++) {
        for(int j = l - 1; j >= 0; j--) {
            if(j % n == i) printf("%c", s[j]);
        }
        printf("\n");
    }

}


L1-2 大笨钟(10 分)

微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当当当当当当当当当”。在午夜00:00到中午12:00期间(端点时间包括在内),笨钟是不敲的。

下面就请你写个程序,根据当前时间替大笨钟敲钟。

输入格式:

输入第一行按照hh:mm的格式给出当前时间。其中hh是小时,在00到23之间;mm是分钟,在00到59之间。

输出格式:

根据当前时间替大笨钟敲钟,即在一行中输出相应数量个Dang。如果不是敲钟期,则输出:

Only hh:mm.  Too early to Dang.

其中hh:mm是输入的时间。

输入样例1:

19:05

输出样例1:

DangDangDangDangDangDangDangDang

输入样例2:

07:05

输出样例2:

Only 07:05.  Too early to Dang.

思路:直接根据题意暴力啦~~~

本人AC代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int h, m;
char c;

int main() {
    scanf("%d %c %d", &h, &c, &m);
    if(h >= 0 && h <= 12) {
        if(m >= 0 && m <= 9 && h >= 0 && h <= 9) printf("Only 0%d:0%d.  Too early to Dang.\n", h, m);
        else if(m >= 0 && m <= 9 && h > 9) printf("Only %d:0%d.  Too early to Dang.\n", h, m);
        else if(h >= 0 && h <= 9 && m > 9) printf("Only 0%d:%d.  Too early to Dang.\n", h, m);
        else printf("Only %d:%d.  Too early to Dang.\n", h, m);
    }
    else {
        if(m == 0) {
            for(int i = 1; i <= h % 12; i++) printf("Dang");
            putchar ('\n');
        }
        else {
            if(h == 23) {
                for(int i = 1; i <= 12; i++) printf("Dang");
                putchar('\n');
            }
            else {
                for(int i = 1; i <= (h + 1) % 12; i++) printf("Dang");
                putchar('\n');
            }
        }
    }

}


L1-4 情人节(15 分)

以上是朋友圈中一奇葩贴:“2月14情人节了,我决定造福大家。第2个赞和第14个赞的,我介绍你俩认识…………咱三吃饭…你俩请…”。现给出此贴下点赞的朋友名单,请你找出那两位要请客的倒霉蛋。

输入格式:

输入按照点赞的先后顺序给出不知道多少个点赞的人名,每个人名占一行,为不超过10个英文字母的非空单词,以回车结束。一个英文句点.标志输入的结束,这个符号不算在点赞名单里。

输出格式:

根据点赞情况在一行中输出结论:若存在第2个人A和第14个人B,则输出“A and B are inviting you to dinner...”;若只有A没有B,则输出“A is the only one for you...”;若连A都没有,则输出“Momo... No one is for you ...”。

输入样例1:

GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.

输出样例1:

Magi and Potaty are inviting you to dinner...

输入样例2:

LaoLao
FatMouse
whoever
.

输出样例2:

FatMouse is the only one for you...

输入样例3:

LaoLao
.

输出样例3:

Momo... No one is for you ...

思路:当然也是直接根据题意暴力了啦~~~

AC代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
char s[30][30];

int main() {
    int p;
    for(int i = 1; ; i++) {
        scanf("%s", s[i]);
        if(s[i][0] == '.') {
            p = i;
            break;
        }
    }
    int n = p - 1;
    if(n < 2) puts("Momo... No one is for you ...");
    else if(n >= 2 && n < 14) printf("%s is the only one for you...\n", s[2]);
    else printf("%s and %s are inviting you to dinner...\n", s[2], s[14]);

}


L1-5 I Love GPLT(5 分)

这道超级简单的题目没有任何输入。

你只需要把这句很重要的话 —— I Love GPLT ——竖着输出就可以了。

所谓“竖着输出”,是指每个字符占一行(包括空格),即每行只能有1个字符和回车。

思路:咳咳,这题你要是不会,恭喜你,你和ACM无缘。。。

AC代码:

#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    puts("I");
    puts(" ");
    puts("L");
    puts("o");
    puts("v");
    puts("e");
    puts(" ");
    puts("G");
    puts("P");
    puts("L");
    puts("T");

}


L1-6 是不是太胖了(5 分)

据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。已知市斤是公斤的两倍。现给定某人身高,请你计算其标准体重应该是多少?(顺便也悄悄给自己算一下吧……)

输入格式:

输入第一行给出一个正整数H(100 < H 300),为某人身高。

输出格式:

在一行中输出对应的标准体重,单位为市斤,保留小数点后1位。

输入样例:

169

输出样例:

124.2

思路:题意已经说得很清楚啦~那就不留情面的直接暴力过掉它~让它知道,过它就像过凌晨的马路一样轻松~

AC代码:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
double ans;

int main() {
    scanf("%d", &n);
    ans = (n - 100) * 1.8;
    printf("%.1lf\n", ans);

}


L1-7 到底是不是太胖了(10 分)

据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。真实体重与标准体重误差在10%以内都是完美身材(即 | 真实体重 标准体重 | < 标准体重×10%)。已知市斤是公斤的两倍。现给定一群人的身高和实际体重,请你告诉他们是否太胖或太瘦了。

输入格式:

输入第一行给出一个正整数N 20)。随后N行,每行给出两个整数,分别是一个人的身高H(120 < H < 200;单位:厘米)和真实体重W(50 < W 300;单位:市斤),其间以空格分隔。

输出格式:

为每个人输出一行结论:如果是完美身材,输出You are wan mei!;如果太胖了,输出You are tai pang le!;否则输出You are tai shou le!

输入样例:

3
169 136
150 81
178 155

输出样例:

You are wan mei!
You are tai shou le!
You are tai pang le!

思路:

这题简直了。。。我编译器莫名失精挫掉。。。当然也是暴力过的啦~~~

AC代码:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int cas;
int a;
float b;

int main() {
    scanf("%d", &cas);
    while(cas--) {
        scanf("%d %f", &a, &b);
        float lev = (a - 100) * 1.8; //标准市斤
        if(b >= lev) {
            if(b - lev < lev * 0.1) puts("You are wan mei!");
            else puts("You are tai pang le!");
        }
        else if(b <= lev) {
            if(lev - b < lev * 0.1) puts("You are wan mei!");
            else puts("You are tai shou le!");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/EricGipsy/article/details/80056552