计算机天梯赛pat练习集L1-(31~88题)

31、到底是不是太胖了

// 时间:2022.04.13 22点48分
#include<iostream>
#include<cmath>
using namespace std;
int m;
void check(int h,float w)
{
   
    //计算标准体重
    float ww=(h-100)*0.9;

    //| 真实体重 − 标准体重 | < 标准体重×10%
    if(abs(ww-w)<(ww*0.1)){
   
        cout<<"You are wan mei!"<<endl;
        return;}
    if((w-ww)>=(ww*0.1)){
   
        cout<<"You are tai pang le!"<<endl;
        return;}
     if((ww-w)>=(ww*0.1)){
   
        cout<<"You are tai shou le!"<<endl;
         return;}
}
int main ()
{
   
    cin>>m;
    while(m--)
    {
   
        int h,w;//h代表身高,w代表体重
        cin>>h>>w;
        check(h,w/2.0);
    }
    return 0;
}

32、Left-pad

// 时间:2022.04.13 23点27分
#include<iostream>
#include<string>
using namespace std;
int n;
char c;
string str;
int main ()
{
   
    //cin>>n>>c;
    scanf("%d %c",&n,&c);
    getchar();//www,没加这个导致一直无法读入字符串,需要用这个来吸收之前的换行符
    getline(cin,str);
    //cout<<"n:"<<n<<" c:"<<c<<" str:"<<str.size()<<endl;
    //cout<<str<<endl;
    if(n==str.size())//不用填充的情况-原样输出即可
    {
   
        cout<<str<<endl;
    }
    if(n<str.size())//不用填充的情况-需要进行截断
    {
   
        for(int i=str.size()-n;i<str.size();i++)
            cout<<str[i];
        cout<<endl;
    }
    if(n>str.size())//需要进行填充
    {
   

        for(int i=1;i<=(n-str.size());i++)
            cout<<c;
        for(int i=0;i<str.size();i++)
            cout<<str[i];
        cout<<endl;
    }
    return 0;
}

33、出生年

// 时间:2022.04.14 20点23分
#include<iostream>
#include<string.h>
#include<set>
using namespace std;

int main ()
{
   
    int y,n;
    cin>>y>>n;
    
    int ans=0;
    set<int>ms;
    for(int i=y;i<3020;i++)//注意此处的范围,不能到3000就截至,因为y有可能取到3000
    // 当n等于2 结果为0 3000 当n等于3 结果为1 3001 当n等于4 结果为12 3012 
    //所以这里的循环必须大于等于3012,只取3000测试点2扣一分   
    {
   
        ms.clear();
        int num=i;
         for(int j=0;j<4;j++)
        {
   
            ms.insert(num%10);//以此从个位往高位添加,且还可以自动加0
            num/=10;
        }
        if(ms.size()==n){
   
           printf("%d %04d\n",ans,i);
            break;}
        ans++;
    }
    return 0;
}

34、点赞

// 时间:2022.04.15 21点59分
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
vector<int>mv;
bool bv[1010];//用来判断重复
int main ()
{
   
    cin>>n;
    for(int i=1;i<=n;i++)
    {
   
        int k=0,ret=0;
        cin>>k;
        for(int j=1;j<=k;j++){
   
            cin>>ret;
            mv.push_back(ret);
        }
    }
   // sort(mv.begin(),mv.end());//将所有的数进行一个排序,然后从后面
    int mmax=-1,ans=0;//mmax代表出现的次数,ans代表那个数
    for(int i=mv.size()-1;i>=0;i--)
    {
   
        int sum=0;
        if(bv[mv[i]]==0){
   //之前没有碰到过才进行查找
        for(int q=0;q<mv.size();q++)
            if(mv[q]==mv[i])
                sum++;
         //判断这个数出现的次数
        if(sum>mmax)
        {
   
            ans=mv[i];
            mmax=sum;
        }
           bv[mv[i]]=1;
        }
    }
   cout<<ans<<" "<<mmax<<endl;
    return 0;
}

35、情人节

// 时间:2022.04.15 22点24分
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<string>mv;
int main ()
{
   
    string str;
    while(1){
   
        str.clear();
        cin>>str;
        if(str[0]=='.')
            break;
        mv.push_back(str);
    }
    if(mv.size()>=14){
   //存在A和B
        cout<<mv[1]<<" and "<<mv[13]<<" are inviting you to dinner..."<<endl;
        return 0;
    }
    if(mv.size()>=2 && mv.size()<13){
   //只有A没有B
        cout<<mv[1]<<" is the only one for you..."<<endl;
        return 0;
    }
    if(mv.size()<2){
   //连A都没有
    cout<<"Momo... No one is for you ..."<<endl;
    }
    return 0;
}

36、A乘以B

// 时间:2022.04.15 22点26分
#include<iostream>
using namespace std;

int main ()
{
   
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

37、A除以B

// 时间:2022.04.15 22点39分
#include<iostream>
using namespace std;
int main ()
{
   
    int a,b;
    cin>>a>>b;
    if(b==0)
        printf("%d/0=Error\n",a);
    if(b>0)
        printf("%d/%d=%.2f\n",a,b,a/(b*1.0));
    if(b<0)
        printf("%d/(%d)=%.2f\n",a,b,a/(b*1.0));
    return 0;
 
}

38、新世界

// 时间:2022.04.15 22点41分
#include<stdio.h>
int main ()
{
   
    printf("Hello World\nHello New World\n");
    return 0;
}

39、古风排版

//  时间:2022.05.17 20点57分
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main ()
{
   
    int n,col;//col记录列数
    cin>>n;
    getchar();
    string str;
    getline(cin,str);
    //1、计算列数
    if(str.size()%n==0)
       col=str.size()/n;
    else{
   
        col=str.size()/n+1;
        //补余数个空格
        for(int i=0;i<str.size()%n;i++)
                str+=' ';
    }
    string arr[col];//记录切割后的字符串数组
    //2、切割字符串
    for(int i=0;i<col;i++){
   
        string temp;
        for(int j=i*n;j<i*n+n;j++)
            temp+=str[j];
        arr[i]=temp;
    }
    
    //3、输出
    for(int i=0;i<n;i++){
   
        for(int j=col-1;j>=0;j--)
            cout<<arr[j][i];
        cout<<endl;
    }
    return 0;
}

40、最佳情侣身高差

// 时间:2022.05.17 21点04分
#include<iostream>
using namespace std;
int main ()
{
   
    int n;
    cin>>n;
    while(n--)
    {
   
        char op[2];
        float h;
        cin>>op>>h;
        //cout<<op<<" "<<h<<endl;
        //女方的身高)×1.09 =(男方的身高)
        if(*op=='F'){
   //查询的是女生
            printf("%.2f\n",h*1.09);
        }
        else if(*op=='M'){
   //查询的是男生
            printf("%.2f\n",h/1.09);
        }
    }
    return 0;
}

41、寻找250

// 时间:2022.05.17 21点20分
#include<iostream>
using namespace std;

int main ()
{
   
    int n;
    int i=1;
    while(cin>>n){
   
        if(n==250)
            break;
       i++;
    }
    cout<<i<<endl;
    return 0;
}

42、日期格式化

//  时间:2022.05.17 21点29分
#include<iostream>
using namespace std;
int main ()
{
   
    int yy,mm,dd;
    scanf("%d-%d-%d",&mm,&dd,&yy);
    printf("%d-%02d-%02d\n",yy,mm,dd);//唯一需要注意的地方是这里的需要补0
    return 0;
}

43、阅览室

// 阅览室       20分
#include <stdio.h>

// 每条数据记录该有的信息
typedef struct Book
{
   
    int wasBorrow;
    char operate;
    int hour;
    int min;
}Book;

int main (void)
{
   
    int days, count, times, id;
    id = days = count = times = 0;
    // 存储每本书的借还情况
    Book records[1005], temp;
    scanf("%d", &days);
    while (days--)
    {
   
        while (1)
        {
   
            scanf("%d %c %d:%d", &id, &temp.operate, &temp.hour, &temp.min);
            if (0 == id)
                break;
            // 读取的操作如果是归还的话
            else if ('E' == temp.operate)
            {
   
                if (records[id].wasBorrow == 1)
                {
   
                    count++;
                    times += (temp.hour - records[id].hour) * 60 + temp.min - records[id].min;
                    records[id].wasBorrow = 0;
                }
            }
            // 读取的操作如果是借阅的话
            else if ('S' == temp.operate)
            {
   
                records[id] = temp;
                records[id].wasBorrow = 1;
            }
        }
        // 当天数据处理完之后输出结果
        if (0 == count)
            printf("0 0\n");
        else
            printf("%d %d\n", count, (int)((double)times/count+0.5));
        // 初始化一些该初始化的值
        count = times = 0;
        for (int i = 0; i < 1005; i++)
            records[i].wasBorrow = 0;
    }
    return 0;
}

44、稳赢

//时间:2022.05.17 23点45分
#include<iostream>
#include<string>
using namespace std;
int main ()
{
   
    string str;
    int n;
    cin>>n;
    while(1)
    {
   
        for(int i=1;i<=n+1;i++){
   //以n=1为周期循环
        cin>>str;
        if(str=="End")
            return 0;
            if(i==n+1){
   
                cout<<str<
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值