武汉工程大学2020GPLT选拔赛(重现赛)L1-1-L1-8

A   L1-1 I LOVE WIT 

思路:用两个for循环输出即可

#include<bits/stdc++.h>
using namespace std;

int main(){
    string s = "I LOVE WIT";
    for(int i=0;i<s.size();i++){
        for(int j=0;j<i;j++){
            cout<<" ";
        }
        cout<<s[i]<<endl;
    }
    return 0;
}

B   L1-2 单位换算 

思路:按题意换算即可,注意判断是否为整数

#include<bits/stdc++.h>
using namespace std;

int main(){
    double x;
    cin>>x;
    double cun = 12,li = 2.54,hao = 10;
    double ans = x*cun*li*hao;
    double bi = (int)ans;
    if(bi!=ans || ans-bi>=0.1){
        printf("%.1lf",ans);
    }
    else{
        cout<<bi;
    }
    return 0;
}

 C   L1-3 Pok&eacute;mon

思路:scanf printf按格式输入输出即可,注意%的转义是%%

#include<bits/stdc++.h>
using namespace std;

int main(){
    double drr[7];
    for(int i=0;i<7;i++){
        scanf("%lf%%",drr+i);
    }
    int c,f;
    cin>>c>>f;
    if(f){
        printf("%.2lf%%",drr[c]*0.01);
    }
    else{
        printf("%.2lf%%",drr[c]*0.99);
    }
    return 0;
}

D   L1-4 颠倒阴阳

思路:建立一个字符串,然后十进制转二进制,注意计数,按计数反转后再二进制转十进制即可

#include<bits/stdc++.h>
using namespace std;

#define int unsigned long long

signed main(){
    string s = "800000000000000000000000000000000";
    int x;
    cin>>x;
    int cnt=1;
    while(x){
        if(x%2) s[cnt]='1';
        x/=2;
        cnt++;
    }
    for(int i=1;i<cnt;i++){
        if(s[i]=='1') s[i]='0';
        else s[i]='1';
    }
    int ans=0;
    for(int i=1;i<=32;i++){
        if(s[i]=='1') ans += pow(2,32-i);
    }
    cout<<ans;
    return 0;
}

 E   L1-5 演唱会

思路:将时间统一转化成秒数进行判断即可

#include<bits/stdc++.h>
using namespace std;

int main(){
    int aa,bb,cc;
    scanf("%d:%d:%d",&aa,&bb,&cc);
    int miao = aa*3600+bb*60+cc;
    int dao = 19*3600;
    int jie = 21*3600;
    int yao = 3600+22*60+33;
    if(miao+yao<dao) cout<<"arrive on time";
    else if(miao+yao>=jie) cout<<"too late";
    else cout<<"arrive late";
    return 0;
}

 F   L1-6 分鸽子

思路:将数组排序后进行二分,判断mid是否满足条件即可

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,p;
    cin>>n>>p;
    vector<int> grr(n+1,0);
    for(int i=1;i<=n;i++) cin>>grr[i];
    sort(grr.begin()+1,grr.end());
    int l = 1,r = grr[n];
    int mid=0,ans=0;
    while(l<=r){
        mid=(l+r)/2;
        int cnt = 0;
        for(int i=1;i<=n;i++){
            cnt += grr[i]/mid;
        }
        if(cnt>=p){ans = mid; l=mid+1;}
        else r=mid-1;
    }
    cout<<ans<<endl;
    return 0;
}

G   L1-7 拼接梯子

思路:将L转化成二进制来处理,因为没有给出2^0长度的木棍,所以L为奇数时一定不行,随后看L的二进制最高位是否不大于2^k即可

#include<bits/stdc++.h>
using namespace std;

#define int int64_t

signed main(){
    int k,x,xx;
    int er = 2;
    cin>>k>>x;
    xx=x;
    string s = "9";
    int cnt = 0;
    while(x){
        if(x%2) s += "1";
        else s += "0";
        cnt++;
        x/=2;
    }
    cnt--;
    //cout<<s<<" "<<cnt<<endl;
    if(xx%2 || cnt>k) cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        cout<<(int64_t)pow(er,cnt)<<endl;
    }
    return 0;
}

H   L1-8 幻想乡炼金学

思路:硬模拟............

#include<bits/stdc++.h>
using namespace std;

int i=0;

string atom(const string& s,int& i)
{
    string t;
    t+=s[i++];
    while (i<(int)s.size() && s[i]>='a' && s[i]<='z') {
        t+=s[i++];
    }
    return t;
}
int num(const string& s,int& i)
{
    int n=0;
    while (i<(int)s.size() && s[i]>='0' && s[i]<='9') {
        n=n*10+s[i++]-'0';
    }
    return n;
}

int main()
{
    string str,s;
    getline(cin,str);
    for (int i=0;i<(int)str.size();i++) {
        if (str[i]!=' ') {
            s+=str[i];
        }
    }

    string ans;
    for (;i<s.size();) {
        if (s[i]>='A' && s[i]<='Z') {
           string a=atom(s,i);
            if (i<s.size() && s[i]=='{') {
                i++;
                int m=num(s,i);
                i++;
                for (int j=0;j<m;j++) {
                    cout<<a;
                }
            } else {
                cout<<a;
            }
        } else if (s[i]=='(') {
            vector<string> v;
            i++;
            while (i<s.size() && s[i]!=')') {
                v.push_back(atom(s,i));
            }
            i+=2;
            int m=num(s,i);
            i++;
            for (int j=0;j<(int)v.size();j++) {
                for (int k=0;k<m;k++) {
                    cout<<v[j];
                }
            }
        }
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值