【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分)
#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;
}