【PTA】团体程序设计天梯赛L1

【PTA】团体程序设计天梯赛L1代码合集,陆续完善中.......

题目描述就不放了,放一下代码存个档,顺便复习复习。

以下代码均能AC。

L1-001 Hello World(5分)

#include<iostream>

using namespace std;

int main()
{
    cout << "Hello World!" << endl;
    return 0;
}

L1-002 打印沙漏(20分)

#include<bits/stdc++.h>

using namespace std;
int n;
char ch;

int main()
{
    cin>>n>>ch;
    int t,t1=0,flag,kg=0;
    if(n==1) cout<<ch<<endl<<"0"<<endl;//1 要特殊考虑       
    else
    {
    for(int i=1;i<=n;i++)
    {
        
        flag=i-1;           //flag记录从第一行到单独输出*的行数
        t+=2*(2*i-1);
        if((t-1)>n) break;
        t1+=2*(2*i-1);
    }
    int s=2*flag-1;
    for(int i=flag;i>0;i--)
    {
        int s1=2*i-1;
        kg=(s-s1)/2;
        while(kg--) cout<<" ";
        while(s1--) cout<<ch;
        cout<<endl;
    }
    for(int i=2;i<=flag;i++)
    {
        int s2=2*i-1;
        kg=(s-s2)/2;
        while(kg--) cout<<" ";
        while(s2--) cout<<ch;
        cout<<endl;
    }
    t1=n-t1+1;
    cout<<t1<<endl;
    }
    return 0;
}

L1-004 计算摄氏温度 (5分) 

#include<bits/stdc++.h>

using namespace std;

int c, f;

int main()
{
    cin >> f;
    c = 5 * (f-32) / 9;
    printf("Celsius = %d\n", c );
    
    return 0;
}

L1-061 新胖子公式 (10分) 

#include<bits/stdc++.h>

using namespace std;

double w, t;

int main()
{
    cin >> w >> t;
    double x = w / (t * t);

    if(x <= 25) printf("%.1lf\nHai Xing\n", x );
    else printf("%.1lf\nPANG\n", x );
    
    return 0;
}

L1-087 机工士姆斯塔迪奥 (20分)

题解见http://t.csdnimg.cn/qlGNm

#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;  //注意范围 上限是行*列的范围 而不是q的范围

int n, m, q;
int t, c;
bool row[N], col[N];    //标记BOSS对行或列的技能释放状态

int main()
{
    scanf( "%d%d%d" , &n, &m, &q);
 
    while( q -- )
    {
        cin >> t >> c;
        if( t == 0 ) row[c] = true;
        else col[c] = true;
    }
   
    int ans = 0 ;
    
    //注意 行和列的编号是从1开始
    for(int i = 1; i <= n; i ++ )
        for(int j = 1; j <= m; j ++ )
        {
            if(!row[i] && !col[j]) ans ++; //行和列都没有被释放过技能的格子就是安全格子
        }
    cout << ans <<endl;
    
    return 0;
}

L1-092 进化论 (10分)

#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int n;
int a, b, c;

int main()
{
    cin >> n;
    while(n -- )
    {
        cin >> a >> b >> c;
        
        if( c == a * b) cout << "Lv Yan" << endl;
        else if( c == a + b) cout << "Tu Dou" << endl;
        else cout << "zhe du shi sha ya!" << endl;
        
    }
    return 0;
}

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值