PAT : 团体程序设计天梯赛-练习集 L1 答案

 

鉴定完毕!全是水题!

补::ios

2019-03-31 :参加了昨天的天梯赛,只得了153分,队伍勉强得的国三省二…第一阶段的最后一题太难了啊啊啊啊,直接爆炸!git

            说好的第一阶段全是水题呐?dom

目录

L1-001Hello World(lua)

L1-002打印沙漏(C)

L1-003个位数统计(C)

L1-004计算摄氏温度(C)

L1-005考试座位号(C++11)

L1-006连续因子(C++11)

L1-007念数字(C)

L1-008求整数段和(C)

L1-009N个数求和(C)

L1-010比较大小(C)

L1-011A-B(C++11)

L1-012计算指数(C)

L1-013计算阶乘和(C)

L1-014简单题(Lua)

L1-015跟奥巴马一块儿画方块(C)

L1-016查验身份证(C)

L1-017到底有多二(C)

L1-018大笨钟(C)

L1-019谁先倒(C)

L1-020帅到没朋友(C)

L1-021重要的话说三遍(Lua)

L1-022奇偶分家(C)

L1-023输出GPLT(C)

L1-024后天(C)

L1-025正整数A+B(C)

L1-026I Love GPLT(C)

L1-027出租(C)

L1-028判断素数(C)

L1-029是否是太胖了(C)

L1-030一帮一(C++11)

L1-031究竟是不是太胖了(C++11)

L1-032Left-pad(C++11)

L1-033出生年(C++11)

L1-034点赞(C++11)

L1-035情人节(C)

L1-036A乘以B(C++11)

L1-037A除以B(C++11)

L1-038新世界(Lua)

L1-039古风排版(C++11)

L1-040最佳情侣身高差(C++11)

L1-041寻找250(C++11)

L1-042日期格式化(C++11)

L1-043阅览室(C++11)

L1-044稳赢(C++11)

L1-045宇宙无敌大招呼(C++11)

L1-046整除光棍(C++11)

L1-047装睡(C++11)

L1-048矩阵A乘以B(C++11)

L1-049天梯赛座位分配(C++11)

L1-050倒数第N个字符串(C++11)

L1-051打折(C++11)

L1-0522018咱们要赢(Lua)

L1-053电子汪(C++11)

L1-054福到了(C++11)

L1-055谁是赢家(C++11)

L1-056猜数字(C++11)

L1-057PTA使我神采飞扬(Lua)

L1-0586翻了(C++11)

L1-059敲笨钟(C++11)

L1-060心理阴影面积(C++11)

L1-061新胖子公式(C++11)

L1-062幸运彩票(C++11)

L1-063吃鱼仍是吃肉(C++11)

L1-064估值一亿的AI核心代码(C++11)


L1-001Hello World(lua)

print("Hello World!")

L1-002打印沙漏(C)

#include <stdio.h>
int main(void)
{
    int count;
    char sign;
    scanf("%d %c", &count, &sign);
    int i, s, s_copy;
    for (i = 3, s = 1; count > s; i += 2)
    {
        s_copy = s;
        s += 2 * i;
    }
    int dif = 0;
    if (count != s)
    {
        dif = count - s_copy;
        s = s_copy;
        i -= 2;
    }
    i -= 2;
    int j, i_s;
    for (j = 0; j < i / 2 + 1; j++)
    {
        int i1;
        for (i1 = j; i1 > 0; i1--)
            putchar(' ');
        i_s = i;
        i_s -= j * 2;
        for (; i_s > 0; i_s--)
            putchar(sign);
        printf("\n");
    }
    for (j -= 2; j >= 0; j--)
    {
        int i1;
        for (i1 = j; i1 > 0; i1--)
            putchar(' ');
        i_s = i;
        i_s -= j * 2;
        for (; i_s > 0; i_s--)
            putchar(sign);
        putchar('\n');
    }
    printf("%d\n", dif);
    return 0;
}

L1-003个位数统计(C)

#include <stdio.h>
#include <string.h>

void fun(char *test);

int main(void)
{
    char str[1001];
    scanf("%s", str);
    fun(str);
    return 0;
}
void fun(char *test)
{
    int array[10] = {0};
    int i;
    for (i = strlen(test) - 1; i >= 0; --i)
        array[test[i] - '0']++;
    for (i = 0; i < 10; ++i)
        if (array[i] > 0)
            printf("%d:%d\n", i, array[i]);
}

L1-004计算摄氏温度(C)

#include <stdio.h>
#include <string.h>

void fun(int test);

int main(void)
{
    int i;
    scanf("%d", &i);
    fun(i);
    return 0;
}
void fun(int test)
{
    printf("Celsius = %d\n", (int)(5 * ((double)test - 32) / 9));
}

L1-005考试座位号(C++11)

#include <iostream>
#include <vector>
using namespace std;
using intpair = pair<long long int, int>;
int main(int argc, char *argv[])
{
    int cnt;
    cin >> cnt;
    vector<intpair> vec(cnt + 1);
    while (cnt--)
    {
        long long int tll;
        int a, b;
        cin >> tll >> a >> b;
        vec[a] = {tll, b};
    }
    cin >> cnt;
    while (cnt--)
    {
        int temp;
        cin >> temp;
        cout << vec[temp].first << ' ' << vec[temp].second << endl;
    }
    return EXIT_SUCCESS;
}

L1-006连续因子(C++11)

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    int num, maxlen{0}, maxbeg{0}, maxend{0};
    cin >> num;
    for (int i = 2; i <= static_cast<int>(sqrt(num)); ++i)
    {
        long long int sum = 1;
        int j;
        for (j = i; sum < num; ++j)
        {
            sum *= j;
            if (num % sum == 0)
            {
                if (j - i + 1 > maxlen)
                {
                    maxlen = j - i + 1;
                    maxbeg = i;
                    maxend = j;
                }
            }
        }
    }
    if (!maxlen)
    {
        cout << 1 << endl;
        cout << num << endl;
    }
    else
    {
        cout << maxlen << endl;
        for (int i = maxbeg; i <= maxend; ++i)
            cout << i << (i == maxend ? '\n' : '*');
    }
    return EXIT_SUCCESS;
}

须要注意累乘在输入很大的时候必定会超出 int 范围,所以用 long long int 类型。ide


L1-007念数字(C)

#include<stdio.h>
#include<string.h>
int main(int argc,char* argv[])
{
	typedef char String[100];
	String s;
	scanf("%s", s);
	int i;
	for (i = 0; i < strlen(s); i++)
	{
		char Num = s[i];
		switch (Num)
		{
			case '0':printf("ling"); break;
			case '1':printf("yi"); break;
			case '2':printf("er"); break;
			case '3':printf("san"); break;
			case '4':printf("si"); break;
			case '5':printf("wu"); break;
			case '6':printf("liu"); break;
			case '7':printf("qi"); break;
			case '8':printf("ba"); break;
			case '9':printf("jiu"); break;
			case '-':printf("fu"); break;
			default:printf("error!"); break;
		}
		printf("%c", i < strlen(s) - 1 ? ' ' : '\n');
	}
	return 0;
}

L1-008求整数段和(C)

#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
    int A, B;
    scanf("%d %d", &A, &B);
    int min, max;
    if (A > B){min = B;max = A;}
    else{min = A;max = B;}
    int i, sum;
    for (i = min, sum = 0; i <= max; i++)
    {
        printf("%5d", i);
        if ((i - min + 1) % 5 == 0 && i != min || i == max)
            printf("\n");
        sum += i;
    }
    printf("Sum = %d\n", sum);
    return 0;
}


L1-009N个数求和(C)

#include <stdio.h>
typedef long long ll;
inline ll gcd(ll x, ll y) //求最大公约数
{
    return y ? gcd(y, x % y) : x;
}
void OUTput(ll a, ll b) //按照格式来去输出
{
    ll e = a / b;
    a -= e * b;
    if (e == 0 && a == 0)
        printf("0");
    if (e != 0)
        printf("%lld", e);
    if (a != 0 && e != 0)
        printf(" ");
    if (a != 0)
        printf("%lld/%lld", a, b);
    return;
}
int main()
{
    ll n;
    ll a, b, c, d;
    scanf("%lld", &n);
    scanf("%lld/%lld", &a, &b);
    for (int i = 1; i <= n - 1; i++)
    {
        scanf("%lld/%lld", &c, &d);
        ll g = gcd(b, d);    //两个分母的最大公约数
        ll mul = b / g * d;  //两个分母的最小公倍数
        ll e1 = mul / b;     //第一个分数扩大的倍数
        ll e2 = mul / d;     //第二个分数扩大的倍数
        a = a * e1 + c * e2; //相加后的分子
        b = mul;
        if (a != 0) //排除当分子为零的状况
        {
            ll gg = gcd(a, b);
            a /= gg;
            b /= gg;
        }
    }
    OUTput(a, b);
    return 0;
}


L1-010比较大小(C)

#include<stdio.h>
void swap(int* x, int* y);

int main(int argc, char* argv[])
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a > b)
		swap(&a, &b);
	if (a > c)
		swap(&a, &c);
	if (b > c)
		swap(&b, &c);
	printf("%d->%d->%d\n", a, b, c);
	return 0;
}
void swap(int* x, int* y)
{
	*x += *y;
	*y = *x - *y;
	*x -= *y;
}


L1-011A-B(C++11)

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    string str, sub;
    getline(cin, str);
    getline(cin, sub);
    bool book[128]{false};
    for (const auto i : sub)
        book[i] = true;
    for (const auto i : str)
        if (book[i] == false)
            cout << i;
    return EXIT_SUCCESS;
}


L1-012计算指数(C)

#include<stdio.h>
#include<stdlib.h>
int main(int argc,char* argv[])
{
	int n;
	scanf("%d",&n);
	int res = 1;
	for(int i=0;i<n;i++)
		res*=2;
	printf("2^%d = %d\n",n,res);
	return EXIT_SUCCESS;
}


L1-013计算阶乘和(C)

#include<stdio.h>
#include<stdlib.h>
int main(int argc,char* argv[])
{
	int n;
	scanf("%d",&n);
	int res = 1, sum = 0;
	for(int i=1;i<=n;i++)
	{
		res *= i;
		sum += res;
	}
	printf("%d\n",sum);
	return EXIT_SUCCESS;
}


L1-014简单题(Lua)

print("This is a simple problem.")


L1-015跟奥巴马一块儿画方块(C)

#include<stdio.h>
#include<stdlib.h>
#define divide(n) (n/2.0-n/2)?n/2+1:n/2
int main(int argc,char* argv[])
{
	int n,style;
	scanf("%d %c",&n,&style);
	int m = divide(n);
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
			printf("%c",style);
		printf("\n");
	}
	return EXIT_SUCCESS;
}


L1-016查验身份证(C)

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int func(char* arr);
int main(int argc,char* argv[])
{
    int n;
    int count = 0;
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
	{
        char arr[19];
        scanf("%s",arr);
        count += func(arr);
    }
    if (!count)
        printf("All passed\n");
    return EXIT_SUCCESS;
}
int func(char* arr)
{
    int sum = 0;
    char a[18];
    for (int i = 0; i < 17; i++)
    {
    	if(!isdigit(arr[i]))
    	{
        	printf("%s\n",arr);
        	return EXIT_FAILURE;
    	}
    	a[i] = arr[i] - '0';
    }
    if (arr[17] == 'X')
        a[17] = 10;
    else
        a[17] = arr[17] - '0';
    int b[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    for (int i = 0; i < 17; i++)
        sum = sum + a[i] * b[i];
    sum = sum % 11;
    int c[11] = {1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2};
    if (c[sum] != a[17])
	{
        printf("%s\n",arr);
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}


L1-017到底有多二(C)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
double func(char *arr);
int main(int argc, char *argv[])
{
    char str[60];
    scanf("%s", str);
    printf("%.2lf%%\n", func(str));
    return EXIT_SUCCESS;
}
double func(char *arr)
{
    double len = strlen(arr);
    double even = (arr[(int)len - 1] % 2) ? 1.0 : 2.0;
    double sym = 1.0;
    if (arr[0] == '-')
    {
        sym = 1.5;
        len--;
    }
    double count = 0;
    for (int i = 0; i < strlen(arr); i++)
        if (arr[i] == '2')
            count++;
    double result = (double)count / len * sym * even * 100;
    return result;
}


L1-018大笨钟(C)

#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[])
{
    int hour, min;
    scanf("%d:%d", &hour, &min);
    if(hour < 12||hour == 12&&min == 0)
        printf("Only %02d:%02d.  Too early to Dang.\n", hour, min);
    else
	{
        hour -= 12;
        for(int i = 0; i < hour; i++)
            printf("Dang");
        if(min > 0)
            printf("Dang\n");
    }
    return EXIT_SUCCESS;
}


L1-019谁先倒(C)

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    int as, bs, n;
    scanf("%d%d%d", &as, &bs, &n);
    int max_a = as, max_b = bs;
    while (n--)
    {
        int han_a, han_b, hua_a, hua_b;
        scanf("%d%d%d%d", &han_a, &hua_a, &han_b, &hua_b);
        int sum = han_a + han_b;
        if (sum == hua_a && sum != hua_b)
            as--;
        if (sum == hua_b && sum != hua_a)
            bs--;
        if (as < 0)
        {
            printf("A\n%d\n", max_b - bs);
            break;
        }
        if (bs < 0)
        {
            printf("B\n%d\n", max_a - as);
            break;
        }
    }
    return EXIT_SUCCESS;
}


L1-020帅到没朋友(C)

#include <stdio.h>
#include <string.h>
int per[100000];
int main(int argc, char *argv[])
{
    int n, k, m, count = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &k);
        for (int j = 0; j < k; j++)
        {
            int t;
            scanf("%d", &t);
            per[t] += k - 1;
        }
    }
    scanf("%d", &m);
    int flag = 0;
    for (int i = 0; i < m; i++)
    {
        int t;
        scanf("%d", &t);
        if (per[t] == 0)
        {
            count++;
            if (flag == 0)
            {
                printf("%05d", t);
                flag = 1;
            }
            else
                printf(" %05d", t);
            per[t] = -1;
        }
    }
    if (count == 0)
        printf("No one is handsome\n");
    return 0;
}


L1-021重要的话说三遍(Lua)

print("I'm gonna WIN!")print("I'm gonna WIN!")print("I'm gonna WIN!")


L1-022奇偶分家(C)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main(int argc,char* argv[])
{
	int num;
	scanf("%d",&num);
	int odd,even;
	odd=even=0;
	while(num--)
	{
		int ind;
		scanf("%d",&ind);
		if(ind%2)
			odd++;
		else
			even++;
	}
	printf("%d %d\n",odd,even);
	return EXIT_SUCCESS;
}


L1-023输出GPLT(C)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
char str[10010];
int g,p,l,t;
int main(int argc,char* argv[])
{
	scanf("%s",str);
	int i;
	for(i=0;str[i];i++)
	{
		str[i]=toupper(str[i]);
		if(str[i]=='G')
			g++;
		if(str[i]=='P')
			p++;
		if(str[i]=='L')
			l++;
		if(str[i]=='T')
			t++;
	}
	for(;g|p|l|t;)
	{
		if(g)
		{
			putchar('G');
			g--;
		}
		if(p)
		{
			putchar('P');
			p--;
		}
		if(l)
		{
			putchar('L');
			l--;
		}
		if(t)
		{
			putchar('T');
			t--;
		}
	}
	putchar('\n');
	return EXIT_SUCCESS;
}


L1-024后天(C)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main(int argc,char* argv[])
{
	int num;
	scanf("%d",&num);
	if(num>=1&&num<=5)
		printf("%d\n",num+2);
	else
		printf("%d\n",num-5);
	return EXIT_SUCCESS;
}


L1-025正整数A+B(C)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
char str[1000];
int main(int argc,char* argv[])
{
	scanf("%[^\n]",str);
	int i;
	int num_a,num_b;
	num_a=num_b=0;
	for(i=0;isdigit(str[i]);i++)
	{
		num_a*=10;
		num_a+=str[i]-'0';
	}
	if(str[i]!=' ')
		num_a=-1;
	while(str[i]!=' ')
		i++;
	for(i++;isdigit(str[i]);i++)
	{
		num_b*=10;
		num_b+=str[i]-'0';
	}
	if(str[i]!=0)
		num_b=-1;
	if(num_a<=0||num_a>1000)
		if(num_b<=0||num_b>1000)
			printf("? + ? = ?\n");
		else
			printf("? + %d = ?\n",num_b);
	else
		if(num_b<=0||num_b>1000)
			printf("%d + ? = ?\n",num_a);
		else
			printf("%d + %d = %d\n",num_a,num_b,num_a+num_b);
	return EXIT_SUCCESS;
}


L1-026I Love GPLT(C)

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
    char *str = "I Love GPLT";
    for (int i = 1; i <= 11; i++)
    {
        putchar(str[i - 1]);
        putchar('\n');
    }
    return 0;
}


L1-027出租(C)

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char const *argv[])
{
    bool book[10] = {false};
    int spbook[10] = {0};
    char buffer[20] = {0};
    scanf("%s", buffer);
    for (int i = 0; i < strlen(buffer); i++)
        book[buffer[i]-'0'] = true;
    int index = 0;
    bool fis = false;
    printf("int[] arr = new int[]{");
    for (int i = 9; i >= 0; i--)
    {
        if (book[i])
        {
            spbook[i] = index++;
            if (fis)
                putchar(',');
            else
                fis = true;
            putchar('0' + i);
        }
    }
    printf("};\nint[] index = new int[]{");
    fis = false;
    for (int i = 0; i < strlen(buffer); i++)
    {
        if (fis)
            putchar(',');
        else
            fis = true;
        putchar('0' + spbook[buffer[i] - '0']);
    }
    printf("};\n");
    return 0;
}


L1-028判断素数(C)

#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
bool ispr(int ch)
{
    if (ch < 2)
        return false;
    for (int i = 2; i <= sqrt((double)ch); i++)
        if (ch % i == 0)
            return false;
    return true;
}
int main(int argc, char const *argv[])
{
    int cnt;
    scanf("%d", &cnt);
    while (cnt--)
    {
        int temp;
        scanf("%d", &temp);
        if (ispr(temp))
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


L1-029是否是太胖了(C)

#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char const *argv[])
{
    int high;
    scanf("%d", &high);
    printf("%.1lf\n", (high - 100.0) * 0.9 * 2);
    return 0;
}


L1-030一帮一(C++11)

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
    int cnt;
    cin >> cnt;
    while (cnt--)
    {
        double height, weight;
        cin >> height >> weight;
        weight /= 2;
        double temp{(height - 100.0) * 0.9};
        if ((weight - temp) >= temp * 0.1)
            cout << "You are tai pang le!" << endl;
        else if ((weight - temp) <= temp * -0.1)
            cout << "You are tai shou le!" << endl;
        else
            cout << "You are wan mei!" << endl;
    }
    return EXIT_SUCCESS;
}


L1-031究竟是不是太胖了(C++11)

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
    int cnt;
    cin >> cnt;
    while (cnt--)
    {
        double height, weight;
        cin >> height >> weight;
        weight /= 2;
        double temp{(height - 100.0) * 0.9};
        if ((weight - temp) >= temp * 0.1)
            cout << "You are tai pang le!" << endl;
        else if ((weight - temp) <= temp * -0.1)
            cout << "You are tai shou le!" << endl;
        else
            cout << "You are wan mei!" << endl;
    }
    return EXIT_SUCCESS;
}


L1-032Left-pad(C++11)

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
    unsigned cnt;
    cin >> cnt;
    char ch;
    cin >> ch;
    getchar();
    string str;
    getline(cin, str);
    if (str.size() > cnt)
    {
        auto len = str.size() - cnt;
        cout << str.substr(len) << endl;
    }
    else
        cout << string(cnt - str.size(), ch) << str << endl;
    return EXIT_SUCCESS;
}


L1-033出生年(C++11)

#include <iostream>
bool check(int num,const int &n)
{
	int cnt{3};
	bool dig[10]={false};
	for(int i=1;i<=4;++i)
	{
		int temp{num%10};
		if(dig[temp])
			--cnt;
		else
			dig[temp]=true;
		num/=10;
	}
	if(cnt==n-1)
		return true;
	return false;
}
int main(int argc, char** argv)
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	c=a;
	while(!check(a,b))
		++a;
	printf("%d %04d\n",a-c,a);
	return 0;
}


L1-034点赞(C++11)

#include<iostream>
int main(int argc,char *argv[])
{
	int cnt;
	scanf("%d",&cnt);
	int book[1001]{0},maxn{0},index{-1};
	while(cnt--)
	{
		int cntt;
		scanf("%d",&cntt);
		while(cntt--)
		{
			int temp;
			scanf("%d",&temp);
			++book[temp];
			if(book[temp]>maxn)
				index=temp,maxn=book[temp];
			else if(book[temp]==maxn&&temp>index)
				index=temp;
		}
	}
	printf("%d %d\n",index,maxn);
	return EXIT_SUCCESS;
}


L1-035情人节(C)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char argv[])
{
  	int num = 12;
	char a[num], b[num], str[num];
	int cnt = 0;
	while (scanf("%s",str))
	{
		if (str[0] == '.')
			break;
		cnt++;
		if (cnt == 2) strcpy(a, str);
		if (cnt == 14) strcpy(b, str);
	}
	if (cnt >= 14)
		printf("%s and %s are inviting you to dinner...", a, b);
	else if (cnt <= 1)
		printf("Momo... No one is for you ...");
	else
		printf("%s is the only one for you...", a);
	return EXIT_SUCCESS;
}


L1-036A乘以B(C++11)

#include<iostream>
int main(int argc,char *argv[])
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",a*b);
	return EXIT_SUCCESS;
}


L1-037A除以B(C++11)

#include<iostream>
int main(int argc,char *argv[])
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d/",a);
	if(b<0)
		putchar('(');
	printf("%d",b);
	if(b<0)
		putchar(')');
	putchar('=');
	if(!b)
		printf("Error\n");
	else
		printf("%.2lf\n",a/static_cast<double>(b));
	return EXIT_SUCCESS;
}


L1-038新世界(Lua)

print("Hello World\nHello New World")


L1-039古风排版(C++11)

#include<iostream>
#include<cstring>
#include<cmath>
#define myceil(a,b) (a%b?((a/b)):(a/b-1))
using namespace std;
int main(int argc,char *argv[])
{
	int n;
	char str[1000];
	scanf("%d%*c%[^\n]",&n,str);
	int len{strlen(str)};
	int k{myceil(len,n)};
	for(int i=0;i<n;++i)
	{
		for(int j=k;j>=0;--j)
		{
			if(i+j*n>=len)
				putchar(' ');
			else
				putchar(str[i+j*n]);
		}
		putchar('\n');
	}
	return EXIT_SUCCESS;
}


L1-040最佳情侣身高差(C++11)

#include<iostream>
using namespace std;
int main(int argc,char *argv[])
{
	int n;
	scanf("%d%*c",&n);
	while(n--)
	{
		char ch{getchar()};
		double h;
		scanf("%lf%*c",&h);
		if(ch=='M')
			printf("%.2lf\n",h/1.09);
		else
			printf("%.2lf\n",h*1.09); 
	}
	return EXIT_SUCCESS;
}


L1-041寻找250(C++11)

#include<iostream>
int main(int argc,char *argv[])
{
	int cnt{0};
	while(1)
	{
		++cnt;
		int temp;
		scanf("%d",&temp);
		if(temp==250)
		{
			printf("%d\n",cnt);
			break;
		}
	}
	return EXIT_SUCCESS;
}


L1-042日期格式化(C++11)

#include<iostream>
int main(int argc,char *argv[])
{
	int a,b,c;
	scanf("%d-%d-%d",&a,&b,&c);
	printf("%d-%02d-%02d\n",c,a,b);
	return EXIT_SUCCESS;
}


L1-043阅览室(C++11)

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(int argc,char *argv[])
{
	int day;
	scanf("%d",&day);
	int ind{0},sum{0};
	vector<int> vec(1001,-1);
	while(day)
	{
		int index,hour,min;
		char ch;
		scanf("%d %c %d:%d",&index,&ch,&hour,&min);
		if(!index)
		{
			double outsum=sum;
			if(ind&&ind!=1)
				outsum/=ind;
			printf("%d %.0lf\n",ind,outsum);
			sum=ind=0;
			fill(vec.begin(),vec.end(),-1);
			--day;
			continue;
		}
		if(ch=='S')
			vec[index]=hour*60+min;
		else if(ch=='E'&&vec[index]!=-1)
		{
			++ind;
			sum+=hour*60+min-vec[index];
			vec[index]=-1;
		}
	}
	return EXIT_SUCCESS;
}

很坑。题目并无说清楚借书的时间取最晚时间。ui


L1-044稳赢(C++11)

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(int argc,char *argv[])
{
	int cnt,isp{0};
	cin>>cnt;
	while(1)
	{
		string str;
		cin>>str;
		if(str=="End")
			break;
		if(isp==cnt)
		{
			cout<<str<<endl;
			isp=0;
		}
		else
		{
			if(str=="ChuiZi")
				cout<<"Bu"<<endl;
			else if(str=="Bu")
				cout<<"JianDao"<<endl;
			else
				cout<<"ChuiZi"<<endl;
			++isp;
		}
	}
	return EXIT_SUCCESS;
}


L1-045宇宙无敌大招呼(C++11)

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(int argc,char *argv[])
{
	string str;
	cin>>str;
	cout<<"Hello "<<str<<endl;
	return EXIT_SUCCESS;
}


L1-046整除光棍(C++11)

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(int argc,char *argv[])
{
	int num,cnt{0},base{0};
	cin>>num;
	while(base<num)
		base=base*10+1,++cnt;
	while(1)
	{
		cout<<base/num;
		base%=num;
		if(!base)
			break;
		base=base*10+1;
		++cnt;
	}
	cout<<' '<<cnt<<endl;
	return EXIT_SUCCESS;
}


L1-047装睡(C++11)

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(int argc,char *argv[])
{
	int cnt;
	cin>>cnt;
	while(cnt--)
	{
		string tempstr;
		int a,b;
		cin>>tempstr>>a>>b;
		if(a<15||a>20||b<50||b>70)
			cout<<tempstr<<endl;
	}
	return EXIT_SUCCESS;
}


L1-048矩阵A乘以B(C++11)

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    int m1, n1, m2, n2;
    cin >> m1 >> n1;
    vector<vector<int>> matrix1(m1, vector<int>(n1));
    for (int i = 0; i != m1; ++i)
        for (int j = 0; j != n1; ++j)
            cin >> matrix1[i][j];
    cin >> m2 >> n2;
    vector<vector<int>> matrix2(m2, vector<int>(n2));
    for (int i = 0; i != m2; ++i)
        for (int j = 0; j != n2; ++j)
            cin >> matrix2[i][j];
    if (n1 != m2)
        cout << "Error: " << n1 << " != " << m2 << endl;
    else
    {
        cout << m1 << ' ' << n2 << endl;
        for (int i = 0; i != m1; ++i)
            for (int j = 0; j != n2; ++j)
            {
                int sum{0};
                for (int t = 0; t != n1; ++t)
                    sum += matrix1[i][t] * matrix2[t][j];
                cout << sum << (j == n2 - 1 ? '\n' : ' ');
            }
    }
    return EXIT_SUCCESS;
}


L1-049天梯赛座位分配(C++11)

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    int cnt, sum, isp;
    cin >> cnt;
    vector<int> maxs(cnt + 1);
    for (int i = 1; i <= cnt; ++i)
        cin >> maxs[i], sum += maxs[i];
    vector<vector<int>> book(cnt + 1);
    isp = cnt;
    int index{1};
    while (isp)
    {
        for (int k = 1; k <= 10; ++k)
            for (int i = 1; i <= cnt; ++i)
            {
                if (!maxs[i])
                    continue;
                book[i].push_back(index++);
                if (isp == 1)
                    ++index;
                if (k == 10)
                {
                    --maxs[i];
                    if (!maxs[i])
                        --isp;
                }
            }
    }
    for (int i = 1; i <= cnt; ++i)
    {
        cout << "#" << i << endl;
        for (decltype(book[i].size()) j = 0; j != book[i].size(); ++j)
        {
            cout << book[i][j];
            if ((j + 1) % 10 == 0)
                cout << endl;
            else
                cout << " ";
        }
    }
    return EXIT_SUCCESS;
}

L1-050倒数第N个字符串(C++11)

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    int n, sp;
    cin >> n >> sp;
    --sp;
    vector<char> vec;
    for (int i = 1; i <= n; ++i)
    {
        char ch = 'z' - sp % 26;
        sp /= 26;
        vec.push_back(ch);
    }
    for (auto i = vec.rbegin(); i != vec.rend(); ++i)
        cout << *i;
    return EXIT_SUCCESS;
}

倒着数记得减一,这样就是 0 对应着 zzz 了,一位一位算就是了。lua


L1-051打折(C++11)

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    int a,b;
    cin >> a >> b;
    printf("%.2lf\n", a * b * 0.1);
    return EXIT_SUCCESS;
}


L1-0522018咱们要赢(Lua)

print("2018\nwo3 men2 yao4 ying2 !")


L1-053电子汪(C++11)

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= a + b; ++i)
        cout << "Wang!";
    return EXIT_SUCCESS;
}


L1-054福到了(C++11)

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    char ch;
    int domin;
    cin >> ch >> domin;
    getchar();
    vector<vector<char>> matrix(domin, vector<char>(domin));
    for (int i = 0; i != domin; ++i)
    {
        for (int j = 0; j != domin; ++j)
            matrix[i][j] = getchar();
        getchar();
    }
    bool isp = false;
    for (int i = 0; i != domin / 2; ++i)
    {
        for (int j = 0; j != domin / 2; ++j)
            if (matrix[i][j] != matrix[domin - i - 1][domin - j - 1])
            {
                isp = true;
                break;
            }
        if (isp)
            break;
    }
    if (!isp)
        cout << "bu yong dao le" << endl;
    for (int i = 0; i != domin; ++i)
    {
        for (int j = 0; j != domin; ++j)
        {
            int xi{domin - i - 1}, xj{domin - j - 1};
            if (matrix[xi][xj] == '@')
                cout << ch;
            else
                cout << ' ';
        }
        cout << endl;
    }
    return EXIT_SUCCESS;
}


L1-055谁是赢家(C++11)

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
    int a, b;
    cin >> a >> b;
    int s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    int as = 3 - (s1 + s2 + s3);
    int bs = 3 - as;
    if ((a > b && as) || (a < b && as == 3))
        cout << "The winner is a: " << a << ' ' << '+' << ' ' << as << endl;
    else
        cout << "The winner is b: " << b << ' ' << '+' << ' ' << bs << endl;
    return EXIT_SUCCESS;
}


L1-056猜数字(C++11)

#include<iostream>
using namespace std;
int main(int argc,char *argv[])
{
	int cnt;
	scanf("%d",&cnt);
	char name[10001][10]{0};
	int sum{0},isp[101]={0};
	for(int index=1;index<=cnt;++index)
	{
		scanf("%s",name[index]);
		int temp;
		scanf("%d",&temp);
		isp[temp]=index;
		sum+=temp;
	}
	sum/=cnt;
	sum>>=1;
	printf("%d ",sum);
	for(int i=0;;++i)
	{
		if(sum+i>=0&&sum+i<=100&&isp[sum+i])
		{
			printf("%s\n",name[isp[sum+i]]);
			break;
		}
		else if(i&&sum-i>=0&&sum-i<=100&&isp[sum-i])
		{
			printf("%s\n",name[isp[sum-i]]);
			break;
		}
	}
	return EXIT_SUCCESS;
}

L1-057PTA使我神采飞扬(Lua)

print("PTA shi3 wo3 jing1 shen2 huan4 fa1 !")

L1-0586翻了(C++11)

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
    string str;
    getline(cin, str);
    for (auto it = str.begin(); it != str.end(); ++it)
    {
        if (*it != '6')
            cout << *it;
        else
        {
            auto its = it;
            while (its != str.end() && *its == '6')
                ++its;
            auto sub{its - it};
            if (sub <= 3)
            {
                for (int i = 1; i <= sub; ++i)
                    cout << '6';
            }
            else if (sub > 9)
                cout << "27";
            else
                cout << '9';
            it = its - 1;
        }
    }
    return EXIT_SUCCESS;
}

L1-059敲笨钟(C++11)

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
    int cnt;
    cin >> cnt;
    cin.get();
    while (cnt--)
    {
        string str;
        getline(cin, str);
        auto findex = str.find(',');
        if (findex >= 3 && str.compare(findex - 3, 3, "ong") == 0)
        {
            if (str.compare(str.size() - 4, 3, "ong") == 0)
            {
                decltype(str.size()) findcnt{0}, findindex{str.npos};
                for (auto i = str.size() - 1; i >= 0; --i)
                    if (str[i] == ' ')
                    {
                        ++findcnt;
                        if (findcnt == 3)
                        {
                            findindex = i + 1;
                            break;
                        }
                    }
                str.replace(findindex, str.size() - findindex - 1, "qiao ben zhong");
                cout << str << endl;
                continue;
            }
        }
        cout << "Skipped" << endl;
    }
    return EXIT_SUCCESS;
}

 若是你最后一个样例运行时错误,那么大几率是和我同样没有注意到题中并无指出逗号前必定保证有三个字符……2333。spa

L1-060心理阴影面积(C++11)

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
    int x, y;
    cin >> x >> y;
    int sp{5000};
    sp -= (x * y / 2);
    sp -= ((100 - x) * (100 - y) / 2);
    sp -= (100 - x) * y;
    cout << sp << endl;
    return EXIT_SUCCESS;
}

整数就能够经过~ .net

L1-061新胖子公式(C++11)

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
    double a, b;
    cin >> a >> b;
    auto p = a / (b * b);
    printf("%.1lf\n", p);
    if (p > 25)
        cout << "PANG" << endl;
    else
        cout << "Hai Xing" << endl;
    return EXIT_SUCCESS;
}

L1-062幸运彩票(C++11)

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
    int cnt;
    cin >> cnt;
    while (cnt--)
    {
        cin.get();
        int temp1{0}, temp2{0};
        for (int i = 1; i <= 3; ++i)
            temp1 += cin.get() - '0';
        for (int i = 1; i <= 3; ++i)
            temp2 += cin.get() - '0';
        if (temp1 == temp2)
            cout << "You are lucky!" << endl;
        else
            cout << "Wish you good luck." << endl;
    }
    return EXIT_SUCCESS;
}

L1-063吃鱼仍是吃肉(C++11)

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
    int cnt;
    cin >> cnt;
    while (cnt--)
    {
        bool sex;
        int h, w;
        cin >> sex >> h >> w;
        if (sex)
        {
            if (h < 130)
                cout << "duo chi yu! ";
            else if (h > 130)
                cout << "ni li hai! ";
            else
                cout << "wan mei! ";
            if (w < 27)
                cout << "duo chi rou!" << endl;
            else if (w > 27)
                cout << "shao chi rou!" << endl;
            else
                cout << "wan mei!" << endl;
        }
        else
        {
            if (h < 129)
                cout << "duo chi yu! ";
            else if (h > 129)
                cout << "ni li hai! ";
            else
                cout << "wan mei! ";
            if (w < 25)
                cout << "duo chi rou!" << endl;
            else if (w > 25)
                cout << "shao chi rou!" << endl;
            else
                cout << "wan mei!" << endl;
        }
    }
    return EXIT_SUCCESS;
}

L1-064估值一亿的AI核心代码(C++11)

比较复杂的字符串模拟题,考场上栽在这里了code

单独写了一篇题解:连接

 

END