L1-001 ~ L1-005

L1-001-Hello World

#include<bits/stdc++.h>

using namespace std;

int main()
{
    printf("Hello World!\n");
    
    return 0;
}

L1-002-打印沙漏

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    char c;
    
    scanf("%d %c",&n,&c);
    int m = 0x3f3f3f3f;
    int res;
    int h;
    for(int i = 1 ; i < 30; i++)
    {
         int x = 2 * i * i - 1;
         if(n - x < 0) break;
         if(n - x < m )  { res = x , m = n - x , h = i;}
    }
    
    int t = (h - 1) * 2 + 1;
    
    for(int i = 1 ; i <= h; i++)
    {
        
        for(int k = 1 ; k <= i - 1 ; k++)
        {
            printf(" ");
        }
        
        for(int j = 1 ; j <= 2 * h - 2 * i + 1 ; j++)
        {
            printf("%c",c);
        }
        
        printf("\n");
    }
    
    h = t - h;
    
    for(int i = 1 ; i <= h ; i++)
    {
        for(int k = 1 ; k <= h - i ; k++)
        {
            printf(" ");
        }
        
        for(int j = 1 ; j <= 2 * i + 1 ; j++)
        {
            printf("%c",c);
        }
        printf("\n");
    }
    
    printf("%d\n",n-res);
    
    return 0;
}

L1-003-个位数统计

#include<bits/stdc++.h>

using namespace std;

const int N = 11;
int s[N];

int main()
{
    string str;
    cin>>str;
    
    for(int i = 0 ; i < str.size() ; i++)
    {
        int x = str[i] - '0';
        s[x]++;
    }
    
    for(int i = 0 ; i <= 9 ; i++)
    {
        if(s[i])
        {
            printf("%d:%d\n",i,s[i]);
        }
    }
    return 0;
}

L1-004-计算摄氏温度

#include<bits/stdc++.h>

using namespace std;

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

L1-005-考试座位号

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef pair<string , int> pii;
map <int,pii> m;

int main()
{
    int N;
    cin>>N;
    
    string s;
    int idx;
    int d;
    
    for(int i = 0 ; i < N ; i++)
    {
        cin>>s>>idx>>d;
        m[idx].fi = s;
        m[idx].se = d;
    }
    
    int M;
    cin>>M;
    
    for(int i = 0 ; i < M ; i++)
    {
        int x;
        cin>>x;
        cout<<m[x].fi<<" "<<m[x].se<<endl;
    }
    
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值