团体设计天梯赛L1题解

天梯赛L1题解

L1-001 Hello World

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"Hello World!";
    return 0;
}

L1-002 打印沙漏

首先观察一个沙漏是由两个金字塔重叠顶部构成的,一个金字塔行数为len ,每一行用的符号为2i - 1(正立的) 求和1 + 3 + 5 + ...2len - 1 = len^2

根据总符号数(2*len^2 - 1)计算总行数 2 * len - 1

打印每一行字符即可

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n ;
    cin>>n;
    char c;
    cin>>c;
    int len ;
    for(int i = 1;2*i*i-1<= n ; i++){
        len = i;
    }
    int cnt=2*len*len-1;
    vector<string> ans(2*len-1);
    for(int i = 0;i < len ;i++){
        ans[i] = string(i,' ');
        ans[i]+=string(2*(len-i)-1,c);
        ans[2*(len-1)-i] = ans[i];
    }
    for(auto s:ans){
        cout<<s<<"\n";
    }
    cout<<n-cnt;
    return 0;
}

L1-003 个位数统计

用数组统计即可

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    string n ;cin>>n;
    int cnt[10] ={0};
    for(char c:n){
        int x  =  c-'0';
        cnt[x]++;
    }

    for(int i = 0; i <= 9;i++){
        if(cnt[i]){
            cout<<i<<":"<<cnt[i]<<"\n";
        }
    }
    return 0;
}

L1-004 计算摄氏温度

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n ;
    cin>>n;
    int c = 5*(n-32)/9;
    printf("Celsius = %d",c);
    return 0;
}

L1-005 考试座位号

哈希表 准考证号 ->{试机座位号 考试座位号}

或者结构体

c++ 复制代码
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    unordered_map<int, pair<string, int>> seatMap; // 试机座位号映射准考证号和考试座位号
    
    for (int i = 0; i < n; ++i) {
        string id;
        int testSeat, examSeat;
        cin >> id >> testSeat >> examSeat;
        seatMap[testSeat] = {id, examSeat};
            //make_pair(id, examSeat);
    }
    
    int m;
    cin >> m;
    int seat;
    for (int i = 0; i < m; ++i) {
        cin >> seat;
        // 输出对应准考证号和考试座位号
        cout << seatMap[seat].first << " " << seatMap[seat].second << endl;
    }
    
    return 0;
}

L1-006 连续因子

start 为连续因子的开始第一个数

如果连续因子长度>= 2 只用枚举到sqrt(n) + 1

因为若start > sqrt(n) ,那么start*(start + 1) > n

那么和假设不符 ,长度只能为1输出即可

c++ 复制代码
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int n;
    cin >> n;
    int m = sqrt(n) + 1;
    int start = 0,max_len = 0;
    //连续因子长度>= 2 会进入for循环
    for(int i = 2;i <= m ; i++ ){
        if(n%i != 0)    continue;
        int j = i+1;
        int sum = n/i;
        int len = 1;
        while(sum%j==0 && j<=m){
           sum /= j; 
            len ++;
            j++;
        }
        if(len > max_len){
            start = i;
            max_len = len;
        }
    }
    if(max_len==0){
        //未进入for循环,长度为1
        cout<<1<<endl;
        cout<<n<<endl;
    }
    else{
        cout<<max_len<<endl;
        int f=0;
        for(int i = start ; i< start+max_len;i++){
            if(f)    cout<<"*";
            cout<<i;
            f=1;
        }
    }
    return 0;
}

L1-007 念数字

c++ 复制代码
#include <bits/stdc++.h>

using namespace std;
int main() {
    map<char,string> mp;
    mp['0'] = "ling";
    mp['1'] = "yi";
    mp['2'] = "er";
    mp['3'] = "san";
    mp['4'] = "si";
    mp['5'] = "wu";
    mp['6'] = "liu";
    mp['7'] = "qi";
    mp['8'] = "ba";
    mp['9'] = "jiu";
    mp['-'] = "fu";
    string s;cin>>s;
    int f = 0;
    for(char c:s){
        if(f)cout<<" ";
        cout<<mp[c];
        f=1;
    }
    return 0;
}

L1-008 求整数段和

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int sum =  0;
    int cnt = 0;
    for(int x = a;x <= b;x++){
        printf("%5d",x);
        sum += x;
        cnt++;
        cnt %= 5;
        if(cnt == 0){
            cout << "\n";
        }
    }
    if(cnt != 0) cout << "\n";
    cout << "Sum = " << sum;
    return 0;
}

L1-009 N个数求和

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
    return y == 0 ? x : gcd(y,x % y);
}
int main(){
    int n;
    cin >> n;
    ll a,b,c,d;
    char ignore;
    cin >> a >> ignore >> b;
    for(int i = 0;i < n - 1;i++){
        cin >> c >> ignore >> d;
        a = a*d + b *c;
        b = b*d;
        if(a != 0){
            ll g = gcd(a,b);
            a /= g;
            b /= g;
        }
    }
    ll integer = a / b;
    a -= b * integer;
    if(integer != 0){
        cout << integer;
    }
    if(integer == 0 && a == 0) {
        cout << "0";
    }
    if(integer != 0 && a != 0){
        cout << " ";
    }
    if(a != 0){
        cout << a << "/" << b;
    }
    return 0;
}

L1-010 比较大小

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(3);
    for(int i = 0;i < 3;i++) cin >> a[i];
    sort(a.begin(),a.end());
    for(int i = 0;i < 3;i++){
        if(i ) cout <<"->";
        cout << a[i];
    }
    return 0;
}

L1-011 A-B

哈希表记录一下出现过的字符,出现过的不输出即可

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    getline(cin,a);
    getline(cin,b);
    map<char,bool>vis;
    for(char c:b) vis[c] = true;
    for(char c:a)
    {
        if( vis[c])
        {
            continue;
        }
        cout << c;
    }
    return 0;
}

L1-012 计算指数

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    printf("2^%d = %d",n,1 << n);
    return 0;
}

L1-013 计算阶乘和

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    ll ans = 0;
    ll now = 1;
    for(int i = 1;i <= n;i++){
        now *= i;
        ans += now;
    }
    cout << ans;
    return 0;
}

L1-014 简单题

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"This is a simple problem.";
    return 0;
}

L1-015 跟奥巴马一起画方块

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int col;
    char c;
    cin >> col >> c;
    int row = round(col * 0.5);
    for(int i = 0;i < row;i++){
        for(int j = 0;j < col;j++){
            cout <<c;
        }
        cout << "\n";
        
    }
    return 0;
}

L1-016 查验身份证

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int w[] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    char z[] = {'1','0','X','9','8','7','6','5','4','3','2'};
    bool flag = true;
    for(int i = 0; i < n;i++){
        string s;
        cin >> s;
        bool check = true;
        int sum = 0;
        for(int j = 0;j < 17;j++){
            if(!(s[j] >='0' && s[j] <='9')) {
                check = false;
                break;
            }
            sum += (s[j] - '0')*w[j];
        }

        if(check && z[sum % 11] == s[17]){
            continue;
        }else{
            cout << s << "\n";
            flag = false;
        }
    }
    if(flag) cout << "All passed";
    return 0;
}

L1-017 到底有多二

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool isNeg = false;
    bool isEven = (s[n - 1] - '0')%2 == 0;
    int cnt2 = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == '-') isNeg = true;
        else{
            cnt2 += (s[i] == '2');
        }
    }
    double ans = 1.0*cnt2 / (n - isNeg);
    if(isNeg) ans *= 1.5;
    if(isEven) ans *= 2.0;
    printf("%.2lf%%",100*ans);
    return 0;
}

L1-018 大笨钟

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int hh,mm;
    scanf("%d:%d",&hh,&mm);
    if(hh <= 12){
        printf("Only %02d:%02d.  Too early to Dang.",hh,mm);
    }else{
        int cnt = hh - 12 + ( mm > 0);
        for(int i = 0;i < cnt;i++){
            cout <<"Dang";
        }
    }
    return 0;
}

L1-019 谁先倒

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int n;
    cin >> n;
    int suma = 0,sumb = 0;
    while(n--){
        int han1,hua1,han2,hua2;
        cin >> han1 >> hua1 >> han2 >> hua2;
        int sum = han1 + han2;
        if(sum == hua1 && sum == hua2) continue;
        if(sum == hua1) suma++;
        if(sum == hua2) sumb++;
        if(suma > a) {
            cout << "A\n" << sumb;
            break;
        }else if(sumb > b){
            cout << "B\n" << suma;
            break;
        }
    }
    return 0;
}

L1-020 帅到没朋友

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
bool hasFriend[N];
int main(){
    int n;
    cin >> n;
    memset(hasFriend,false,sizeof hasFriend);
    while(n -- ){
        int k;
        cin >> k;
        for(int i = 0;i < k;i++){
            int x;
            cin >> x;
            if(k > 1) {//有朋友
                hasFriend[x] = true;
            }
        }
    }
    int m;
    cin >> m;
    int count = 0;
    for(int i = 0;i < m;i++){
        int q;
        cin >> q;
        if(!hasFriend[q]){
            if(count > 0) cout << " ";
            count++;
            printf("%05d",q);
            hasFriend[q] = true;// 去重
        }
    }
    if(count == 0){
        cout << "No one is handsome" ;
    }
    return 0;
}
c++ 复制代码
并查集解法(是我刚开始想复杂了)
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int fa[N];
int sz[N];
bool vis[N];
int find(int x){
    return fa[x] = (fa[x] == x ? x : find(fa[x]));
}
void merge(int a,int b){
    int x = find(a),y = find(b);
    if(x == y) return ;
    fa[x] = y;
    sz[y] += sz[x];
}
int main(){
    for(int i = 0; i < N;i++){
        fa[i] = i;
        sz[i] = 1;
    }
    int n;
    cin >> n;
    while(n--){
        int k;
        cin >> k;
        vector<int> a(k);
        for(int i = 0;i < k;i++) cin >> a[i];
        for(int i = 0;i < k - 1;i ++) merge(a[i],a[i + 1]);
    }
    int m;
    cin >> m;
    int cnt = 0;
    while(m--){
        int query;
        cin >> query;
        //cout << find(query) << "\n";
        if(sz[find(query)] == 1 && !vis[query]){
            vis[query] = true;
            if(cnt) cout << " ";
            printf("%05d",query);
            cnt++;
        }
    }
    if(cnt == 0) cout <<"No one is handsome";
    return 0;
}

L1-021 重要的话说三遍

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    printf("I'm gonna WIN!\nI'm gonna WIN!\nI'm gonna WIN!");
    return 0;
}

L1-022 奇偶分家

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int tot = n;
    int odd = 0;
    while(n--){
        int x;
        cin >> x;
        odd += (x & 1);
    }
    cout << odd << " " << tot - odd;
    return 0;
}

L1-023 输出GPLT

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    getline(cin,a);
    unordered_map<char,int> cnt;
    for(char c:a)
    {
        if(c=='g' || c=='G')    cnt['G']++;
        if(c=='p' || c=='P')    cnt['P']++;
        if(c=='L' || c=='l')    cnt['L']++;
        if(c=='t' || c=='T')    cnt['T']++;
    }
    string ans="";
    while(cnt['G']!=0 || cnt['P']!=0 ||cnt['L']!=0 ||cnt['T']!=0 )
    {
        if(cnt['G']!=0)
        {
            ans+='G';
            cnt['G']--;
        }
          if(cnt['P']!=0)
        {
            ans+='P';
            cnt['P']--;
        }
           if(cnt['L']!=0)
        {
            ans+='L';
            cnt['L']--;
        }
           if(cnt['T']!=0)
        {
            ans+='T';
            cnt['T']--;
        }
    }
    cout<<ans;
    return 0;
}

L1-024 后天

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int now = n - 1;
    now = (now + 2) % 7;
    cout << (now + 1);
    return 0;
}

L1-025 正整数A+B

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
bool check(string s){
    if(s.empty() ){
        return false;
    }
    int len = 0;
    int flag = false;
    for(char c : s){
        if(!(c >= '0' && c <= '9')){
            return false;
        }
        if(c != '0') flag = true;
        if(flag) len++;
        if(len > 4) return false;
    }
    int x = stoi(s);
    return (x >= 1 && x <= 1000);
}

int main(){
    string a,b;
    string line;
    getline(cin, line);  // 读取整行输入
    int space_pos = line.find(' ');  // 找到第一个空格的位置
    a = line.substr(0, space_pos);   // A是第一个空格前的部分
    b = line.substr(space_pos + 1);  // B是第一个空格后的部分

    // 你原来的输出逻辑,完全保留,不做任何修改
    if(check(a) && check(b)){
        int x = stoi(a),y = stoi(b);
        printf("%d + %d = %d",x,y, x + y);
    }else if(check(a)){
        int x = stoi(a);
        printf("%d + ? = ?",x);
    }else if(check(b)){
        int y = stoi(b);
        printf("? + %d = ?",y);
    }else{
        printf("? + ? = ?");
    }
    return 0;
}

L1-026 I Love GPLT

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s = "I Love GPLT";
    for(char c : s){
        cout << c << "\n";
    }
    return 0;
}

L1-027 出租

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int cnt[10];
int main(){
    string s ;
    cin >> s;

    for(char c : s){
        cnt[c - '0']++;
    }
    vector<int> arr;
    for(int i = 9;i >= 0;i--){
        if(cnt[i] > 0) arr.push_back(i);
    }
    vector<int> index(11);
    for(int i = 0;i < 11;i++){
        for(int j = 0;j < arr.size();j++){
            if(arr[j] == s[i] - '0'){
                index[i] = j;
                break;
            }
        }
    }
    printf("int[] arr = new int[]{");
    for(int i = 0;i < arr.size();i++){
        if(i) cout <<",";
        cout << arr[i];
    }
    cout <<"};\n";
    printf("int[] index = new int[]{");
    for(int i = 0;i < index.size();i++){
        if(i) cout <<",";
        cout << index[i];
    }
    cout <<"};";
    return 0;
}

L1-028 判断素数

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
bool check(int x){
    if(x < 2) return false;
    for(int i = 2;i <= x / i;i++){
        if(x % i == 0)    return false;
    }
    return true;
}
int main(){
    int n;
    cin >> n;
    while(n--){
        int x ;
        cin >> x;
        if(check(x)) cout<<"Yes\n";
        else cout << "No\n";
    }
    return 0;
}

L1-029 是不是太胖了

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;

int main(){
    int h;
    cin >> h;
    double ans = (h - 100) * 0.9 * 2;
    printf("%.1f",ans);
    return 0;
}

L1-030 一帮一

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> sex(n);
    vector<string> girls;
    vector<string> boys;
    vector<string> name(n);
    for(int i = 0;i < n;i++){
        cin >> sex[i] >> name[i];
        if(sex[i] == 0){
            girls.push_back(name[i]);
        }else{
            boys.push_back(name[i]);
        }
    }
    int sz = n / 2;
    int idx1 = sz,idx2 = sz;
    for(int i = 0;i < sz;i++){
        cout << name[i] << " ";
        if(sex[i] == 0){
            cout << boys[--idx1] << "\n"; 
        }else{
            cout << girls[--idx2] << "\n"; 
        }
    }
    return 0;
}

L1-031 到底是不是太胖了

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    while(n--){
        int h,w;
        cin >> h >> w;
        double s = (h  - 100) * 0.9 * 2;
        if(abs(w - s) < s*0.1){
            cout<< "You are wan mei!\n";
        }else{
            if(w < s){
                cout << "You are tai shou le!\n";
            }
            if(w > s){
                cout << "You are tai pang le!\n";
            }
        }
    }
    return 0;
}

L1-032 Left-pad

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    char c;
    cin >> c;
    cin.ignore();
    string s;
    getline(cin,s);
    if(s.size() <= n){
        string tian(n - s.size(),c);
        s = tian + s;
            cout << s;
    }else{
        cout << s.substr(s.size() - n);
    }

    return 0;
}

L1-033 出生年

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
bool check(int x,int n){
    set<char> st;
    st.clear();
    string s = to_string(x);
    if(s.size() < 4) st.insert('0');
    for(char c : s) st.insert(c);
    return st.size() == n;
}
int main(){
    int n,y;
    cin >> y >> n;
    int ans = 0;
    for(int i = y;i ;i++){
        if(check(i,n)){
            ans  = i;
            break;
        }
    }
    printf("%d %04d",ans - y,ans);
    return 0;
}

L1-034 点赞

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    map<int,int> cnt;
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        int k;
        cin >> k;
        while(k--){
            int f;
            cin >> f;
            cnt[f]++;
        }
    }
    int mx = 0;
    int ans = 0;
    for(auto [x,count] : cnt){
        if(count >= mx){
            mx = count;
            ans = x;
        }
    }
    cout << ans << " " << mx;
    return 0;
}

L1-035 情人节

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(){
    int cnt = 0;
    while(true){
        string s;
        cin >> s;
        if(s == "."){
            break;
        }
        cnt ++;
        if(cnt == 2) a = s;
        if(cnt == 14) b = s;
    }
    if(a.empty()) cout << "Momo... No one is for you ...";
    else if(b.empty()) cout << a <<" is the only one for you...";
    else cout << a << " and " << b << " are inviting you to dinner...";

    return 0;
}

L1-036 A乘以B

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    cout << (a * b);
    return 0;
}

L1-037 A除以B

C++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(b < 0) printf("%d/(%d)=%.2f",a,b,1.0*a/b);
    else if(b == 0) printf("%d/%d=Error",a,b);
    else printf("%d/%d=%.2f",a,b,1.0*a/b);
    return 0;
}

L1-038 新世界

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    cout << "Hello World\n";
    cout << "Hello New World";
    return 0;
}

L1-039 古风排版

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    cin.ignore();
    string s;
    getline(cin,s);
    int sz = s.size();
    int m = (sz + n - 1) / n;
    int idx = 0;
    vector<vector<char>> a(n,vector<char>(m,' '));
    for(int j = m - 1;j >= 0;j--){
        for(int i = 0;i < n;i++){
            a[i][j] = s[idx++];
            if(idx == sz){
                break;
            }
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cout << a[i][j] ; 
        }
        cout << "\n";
    }
    return 0;
}

L1-040 最佳情侣身高差

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    while(n--){
        char sex;
        double h;
        cin >> sex >> h;
        double ans = 0;
        if(sex == 'M'){
            ans = 1.0*h/1.09;
        }else{
            ans = 1.0*h*1.09;
        }
        printf("%.2f\n",ans);
    }
    return 0;
}

L1-041 寻找250

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int cnt = 0;
    while(true){
        int x ;
        cin >> x;
        cnt++;
        if(x == 250) {
            cout<<cnt;
            break;
        }
    }
    return 0;
}

L1-042 日期格式化

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int mm,dd,yy;
    scanf("%d-%d-%d",&mm,&dd,&yy);
    printf("%04d-%02d-%02d",yy,mm,dd);
    return 0;
}

L1-043 阅览室

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int last[3601],vis[3601];
int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        memset(last,0,sizeof last);
        memset(vis,0,sizeof vis);
        int id,hh,mm;
        char op;
        int sumTime = 0,nowTime= 0;
        int avg = 0;
        int cnt = 0;
        while(true){
            scanf("%d %c %d:%d",&id,&op,&hh,&mm);
            nowTime = hh * 60 + mm;
            if(id == 0){
                printf("%d ",cnt);
                if(cnt > 0){
                    avg = round( 1.0*sumTime / cnt );
                }else{
                    avg = 0;
                }
                printf("%d\n",avg);
                break;
            }else if(op == 'S'){
                vis[id] = 1;
                last[id]  = nowTime;
            }else if(op == 'E' && vis[id]){
                sumTime += nowTime - last[id];
                vis[id] = 0;
                cnt++;
            }
        }
    }
}

L1-044 稳赢

C++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    cin >> k;
    map<string,string> win;
    win["ChuiZi"] = "Bu";
    win["Bu"] = "JianDao";
    win["JianDao"] = "ChuiZi";
    int cnt = 0;
    while(true){
        string now;
        cin >> now;
        if(now == "End"){
            break;
        }
        cnt++;
        cnt %= (k + 1);
        if(cnt == 0){
            cout << now << "\n";
        }else{
            cout << win[now] << "\n";
        }
    }
}

L1-045 宇宙无敌大招呼

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    cout<<"Hello " << s;
}

L1-046 整除光棍

模拟除法

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int s = 0,x,digit = 0;  // s:当前构建的光棍数片段(或余数);digit:当前光棍数的位数
    cin >> x;

    // 第一步:构建初始的光棍数片段,直到≥x(除法需要被除数≥除数才能开始算商)
    while(s < x){
        s = s * 10 + 1;  // 每次加一个1(比如1→11→111)
        digit++;         // 位数加1
    }

    // 第二步:模拟除法,逐位算商+更新余数,直到余数为0
    while(1){
        cout << s / x;   // 输出当前商的一位(这是最终s的一位)
        s %= x;          // 取余数(后续用余数补1继续算)
        if(s == 0){      // 余数为0,说明当前光棍数能被x整除,结束
            break;
        }
        s = s * 10 + 1;  // 余数补1(相当于光棍数后面加一个1)
        digit++;         // 位数加1
    }

    cout << " " << digit;  // 输出最终位数
    return 0;
}

L1-047 装睡

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
bool check(int x,int y){
    if(x >= 15 && x <= 20 && y >= 50 && y <= 70) 
        return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    while(n--){
        string name;
        int breath,pulse;
        cin >> name >> breath >> pulse;
        if(!check(breath,pulse)){
            cout << name << "\n";
        }
    }
    return 0;
}

L1-048 矩阵A乘以B

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;

int main() {
    int rA, cA;
    cin >> rA >> cA;
    vector<vector<int>> A(rA, vector<int>(cA));
    for (auto& row : A) for (int& x : row) cin >> x;

    int rB, cB;
    cin >> rB >> cB;
    vector<vector<int>> B(rB, vector<int>(cB));
    for (auto& row : B) for (int& x : row) cin >> x;

    if (cA != rB) {
        cout << "Error: " << cA << " != " << rB;
        return 0;
    }

    vector<vector<int>> C(rA, vector<int>(cB));
    for (int i = 0; i < rA; ++i)
        for (int j = 0; j < cA; ++j)
            for (int k = 0; k < cB; ++k)
                C[i][k] += A[i][j] * B[j][k];

    cout << rA << " " << cB << "\n";
    for (auto& row : C) {
        for (int k = 0; k < row.size(); ++k)
            cout << (k ? " " : "") << row[k];
        cout << "\n";
    }

    return 0;
}

L1-049 天梯赛座位分配

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int id_school[105*1005];
int main() {
    int n;
    cin >> n;
    vector<int> m(n + 1);
    vector<vector<int>> v(n  + 1);
    for(int i = 1; i <= n;i++){
        cin >> m[i];
    }
    int cnt = 1;
    while(true){
        bool flag = true;
        for(int i = 1;i <= n;i++){
            if(v[i].size() < m[i]*10){
                if(id_school[cnt - 1] != i){
                    id_school[cnt] = i;
                    v[i].push_back(cnt);
                    cnt ++;
                }else{
                    id_school[cnt + 1] = i;
                    v[i].push_back(cnt + 1);
                    cnt += 2;
                }
                flag = false;
            }
        }
        if(flag) break;
    }
    for(int i = 1;i <= n;i++){
        cout << "#" << i ;
        for(int j = 0;j < v[i].size();j++){
            if(j % 10 == 0) cout << "\n";
            else cout << " ";
            cout << v[i][j];
        }
        cout << "\n";
    }
    return 0;
}

L1-050 倒数第N个字符串

字符串题转化为26进制 最高位权重最大

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int l,n;
    cin >> l >> n;
    int now = pow(26,l) - n;
    vector<char> a;
    while(now){
        a.push_back((char)((now % 26) + 'a'));
        now /= 26;
    }
    string ans = "";
    for(int i = 0;i < l - (int)a.size();i++){
        ans += 'a';
    }
    for(int i = a.size() - 1;i >= 0;i--){
        ans += a[i];
    }
    cout << ans;
    return 0;
}

L1-051 打折

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    printf("%.2f",1.0*a*b/10);
    return 0;
}

L1-052 2018我们要赢

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    printf("2018\nwo3 men2 yao4 ying2 !");
    return 0;
}

L1-053 电子汪

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    string s = "Wang!";
    for(int i = 0; i < a + b;i++)
    cout  << s;
    return 0;
}

L1-054 福到了

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
char mp[N][N];
char cp[N][N];
int main() {
    char c;
    int n;
    cin >> c >> n;
    cin.ignore();
    for(int i = 0;i < n;i++){
        string s;
        getline(cin,s);
        for(int j = 0;j < n;j++){
            mp[i][j] = s[j];
            cp[n - i - 1][n - j - 1] = s[j];
        }
    }
    bool flag = true;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(mp[i][j] != cp[i][j]){
                flag = false;
                break;
            }
        }
    }
    if(flag)  cout << "bu yong dao le\n";
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(cp[i][j] == '@'){
                cout << c;
            }else {
                cout << cp[i][j];
            }
        }
        cout << "\n";
    }
    return 0;
}

L1-055 谁是赢家

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int pa,pb;
    cin >> pa >> pb;
    int a = 0,b = 0;
    for(int i = 0;i < 3;i++){
        int x;
        cin >> x;
        a += x == 0;
        b += x == 1;
    }
    if(pa > pb){
        if(a > 0){
            printf("The winner is a: %d + %d",pa,a);
        }else{
            printf("The winner is b: %d + %d",pb,b);
        }
    }else{
        if(a > 0){
            printf("The winner is a: %d + %d",pa,a);
        }else{
            printf("The winner is b: %d + %d",pb,b);
        }
    }
    return 0;
}

L1-056 猜数字

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+ 9;
struct{
    string name;
    int score;
}a[N];
int main() {
    int n;
    cin >> n;
    int sum = 0 ;
    for(int i = 0;i< n;i++){
        cin >> a[i].name >> a[i].score;
        sum += a[i].score;
    }
    int avg = sum / n/2;
    string ans;
    int mn = 0x3f3f3f3f;
    for(int i = 0;i< n;i++){
        if(abs(a[i].score - avg) < mn){
            mn = abs(a[i].score - avg);
            ans = a[i].name;
        }
    }
    cout << avg << " " <<ans;
    return 0;
}

L1-057 PTA使我精神焕发

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    cout << "PTA shi3 wo3 jing1 shen2 huan4 fa1 !\n";
    return 0;
}

L1-058 6翻了

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    getline(cin,s);
    int n = s.size();
    for(int i = 0;i < n;i++){
        int start = i;
        int j = i;
        while(j < n && s[j] == '6' && s[j] == s[start]){
            j++;
        }
        if(j == i){
            cout << s[i];
        }else{
            int len = j - start;
            if(len > 3 && len <= 9) cout <<'9';
            else if(len > 9) cout << "27";
            else{
                while(start != j){
                    cout << s[start++];
                }
            }
            i = j - 1;
        }
    }
    return 0;
}

L1-059 敲笨钟

c++ 复制代码
#include<iostream>
using namespace std;
int main(){
	int n,flag;
	cin>>n;
	getchar();//注意
	string s;
	int i=0,j,k;
	while(n--){
		getline(cin,s);
		for(i=0;i<s.size();i++){
			if(s[i]==','){
				if(s[i-1]!='g'||s[i-2]!='n'||s[i-3]!='o'){
					cout<<"Skipped"<<endl;
					break;
				}
				else
				flag=1;
			}
			if(s[i]=='.'){
				if(s[i-1]!='g'||s[i-2]!='n'||s[i-3]!='o'){
					cout<<"Skipped"<<endl;
					break;
				}else{
					if(flag==1){
						k=0;
						j=i;
						while(k!=3) {
							j--;
							if(s[j]==' ')
							k++;	
						}
						s=s.substr(0,j)+" qiao ben zhong.";
						cout<<s<<endl;
						break;
					}
				}
			}
		}
	}
	return 0;
}

L1-060 心理阴影面积

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    cout << (100*a - 100*b)/2;
    return 0;
}

L1-061 新胖子公式

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    double w,h;
    cin >> w >> h;
    double bmi = w / (h*h);
    printf("%.1f\n",bmi);
    if(bmi > 25){
        cout  << "PANG";
    }else{
        cout << "Hai Xing";
    }
    return 0;
}

L1-062 幸运彩票

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    while(n--){
        string x;
        cin >> x;
        int a = 0,b = 0;
        for(int i = 0;i < 6;i++){
            if(i < 3) a += x[i] - '0';
            else b += x[i] - '0';
        }
        if(a == b) cout << "You are lucky!\n";
        else cout << "Wish you good luck.\n";
    }
    return 0;
}

L1-063 吃鱼还是吃肉

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    while(n--){
        int sex,h,w;
        cin >> sex >> h >> w;
        if(sex == 1){
            if(h < 130){
                cout<<"duo chi yu! ";
            }else if(h == 130){
                cout << "wan mei! ";
            }else{
                cout << "ni li hai! ";
            }
            if(w > 27) cout << "shao chi rou!";
            else if(w < 27)cout << "duo chi rou!";
            else cout << "wan mei!";
        }else{
            if(h < 129){
                cout<<"duo chi yu! ";
            }else if(h == 129){
                cout << "wan mei! ";
            }else{
                cout << "ni li hai! ";
            }
            if(w > 25) cout << "shao chi rou!";
            else if(w < 25) cout << "duo chi rou!";
            else cout << "wan mei!";
        }
        cout << "\n";
    }
    return 0;
}

L1-064 估值一亿的AI核心代码

java 复制代码
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        // 读取第一行
        if (sc.hasNextLine()) {
            sc.nextLine();
        }
        
        // 循环读取后续每行输入
        while (sc.hasNextLine()) {
            String s = sc.nextLine();
            System.out.println(s); // 原样打印输入
            System.out.print("AI: ");
            
            // 1. 合并多空格为1个
            s = s.replaceAll(Pattern.quote("\\s+"), " ");
            s = s.replaceAll("\\s+", " ");
            
            // 2. 删首尾空格 + 删标点前的空格
            s = s.replaceAll("^\\s+|\\s+$|\\s+(?=\\W)", "");
            
            // 3. 标记独立的I为mark_mark
            s = s.replaceAll("\\bI\\b", "mark_mark");
            
            // 4. 所有字符转小写(除了原有的I)
            char[] chars = s.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] != 'I') {
                    chars[i] = Character.toLowerCase(chars[i]);
                }
            }
            s = new String(chars);
            
            // 5. 替换can you/could you
            s = s.replaceAll("\\bcan you\\b", "I can");
            s = s.replaceAll("\\bcould you\\b", "I could");
            
            // 6. 替换mark_mark(原I)和me为you
            s = s.replaceAll("mark_mark|\\bme\\b", "you");
            
            // 7. 问号转感叹号
            s = s.replaceAll("\\?", "!");
            
            // 输出结果
            System.out.println(s);
        }
        sc.close();
    }
}

L1-065 嫑废话上代码

python 复制代码
print("Talk is cheap. Show me the code.")

L1-066 猫是液体

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >>c;
    cout<<a*b*c;
    return 0;    
}

L1-067 洛希极限

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    double a,b,c;
    cin >> a >> b >>c;
    double louxi = (b ? 1.26:2.455)*a;
    printf("%.2f ",louxi);
    if(louxi < c) cout<<"^_^";
    else cout<<"T_T";
    return 0;    
}

L1-068 调和平均

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    double sum =  0;
   for(int i = 0;i < n;i++){
        double x;
        cin >> x;
        sum += (1.0)/x;
   }
    double ans = 1.0*n/(sum*1.0);
    printf("%.2f",ans);
    return 0;    
}

L1-069 胎压监测

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(4);
    int mx = 0;
    for(int i = 1;i <= 4;i++) {
        cin >> a[i];
        mx = max(mx,a[i]);
    }
    int mn ,limit;
    cin >> mn >> limit;
    int cnt = 0;
    bool uplimit = true;
    int error;
    for(int i = 1;i <= 4;i++){
        int x = a[i];
        if(x < mn || mx - x > limit){
            cnt ++;
            error = i;
        }
    }
    if(cnt == 0 ){
        cout << "Normal";
    }else if(cnt == 1){
        printf("Warning: please check #%d!",error);
    }else{
        printf("Warning: please check all the tires!");
    }
    return 0;    
}

L1-070 吃火锅

java 复制代码
import java.util.Scanner;
import java.util.regex.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String regex = "chi1 huo3 guo1";
        Pattern pattern = Pattern.compile(regex);
        int tot = 0;
        int first = 0,cnt = 0;
        while(true){
            String line;
            line = sc.nextLine().trim();
            if(".".equals(line)){
                break;
            }
            tot++;
            Matcher matcher = pattern.matcher(line);
            if(matcher.find()){
                if(first == 0)
                    first = tot;
                cnt++;
            }   
        }
        System.out.println(tot);
        if(cnt == 0) {
            System.out.println("-_-#");
        }else{
            System.out.println(first + " " + cnt);
        }
        
        sc.close();
    }
}

L1-071 前世档案

完全二叉树的性质

根节点为1 高度(第一层为1)为i的左孩子节点为2i 右孩子为2i + 1

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    //y 2*i n 2*i+1
    vector<int> ans(m);
    for(int i = 0; i < m;i++){
        string s;
        cin >> s;
        int x = 1;//根节点
        for(int j = 0;j < n;j++){
            x <<= 1;
            x += (s[j] == 'n');
        }
        ans[i] = x - ((1 << n) - 1); // 最后一层从1开始编号,-前n -1层问题总数
    }
    for(int i = 0; i < m;i++){
        cout << ans[i] << "\n";
    }
    return 0;    
}

L1-072 刮刮彩票

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int  a[5][5];
int sum (int flag){
    int tot = 0;
    if(flag >=1 && flag <= 3){
        for(int j  = 1;j  <= 3;j++){
            tot += a[flag][j];
        }
        return tot;
    }else if(flag >=4 && flag <= 6){
        for(int i = 1;i <= 3;i++){
            tot += a[i][flag - 3];
        }
        return tot;
    }
    if(flag == 7){
        for(int i = 1;i <= 3;i++){
            tot += a[i][i];
        }
        return tot;
    }
    for(int i = 1;i <= 3;i++){
            tot += a[4 - i][i];
        }
    return tot;
}
int main(){
    vector<bool> vis(10);
    int money[] = {0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119
                   ,36,306,1080,144,1800,3600};
    int zi,zj;
    for(int i = 1 ; i <= 3;i++){
        for(int j = 1 ;j <= 3;j++){
            cin >> a[i][j];
            if(a[i][j] == 0){
                zi = i;
                zj = j;
            }
            vis[a[i][j]] = true;
        }
    }
    int zero = 0;
    for(int x = 1; x <= 9;x++)    if(!vis[x]) zero = x;
    a[zi][zj] = zero;
    //cout<<zero<<"---------\n";
    for(int i = 0;i < 3;i++){
        int x,y;
        cin >> x >> y;
        cout << a[x][y] <<"\n";
    }
    int flag ;
    cin >> flag;
    //cout<<sum(flag)<<"---------\n";
    int ans = money[sum(flag)];
    cout << ans;
    return 0;    
}

L1-073 人与神

python 复制代码
print("To iterate is human, to recurse divine.")

L1-074 两小时学完C语言

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b>> c;
    int ans = a - b *c;
    cout << ans;
}

L1-075 强迫症

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s ;
    cin >> s;
    if(s.size() == 6){
        cout << s.substr(0,4) << "-"<<s.substr(4);
        return 0;
    }
    string year = s.substr(0,2);
    string month = s.substr(2);
    int yy =  stoi(year),mm = stoi(month);
    if(yy < 22){
        cout <<"20";
    }else{
        cout <<"19";
    }
    printf("%02d-%02d",yy,mm);
    return 0;
}

L1-076 降价提醒机器人

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    double n,m;
    cin >> n >> m;
    while(n--){
        double x;
        cin >> x;
        if(x < m){
            printf("On Sale! %.1f\n",x);
        }
    }
    return 0;
}

L1-077 大笨钟的心情

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
   vector<int> a(24);
   for(int i = 0; i < 24;i++)    cin >> a[i];
   while(true){
       int x;
       cin >> x;
       if(x < 0 || x >= 24)    break;
       cout << a[x];
       if(a[x] > 50) cout <<" Yes\n";
       else cout << " No\n";
   }
   return 0;
}

L1-078 吉老师的回归

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin  >> n >> m;
    cin.ignore();
    int cnt = 0;
    string ans = "Wo AK le";
    while(n--){
        string s;
        getline(cin,s);
        if(s.find("easy") == string::npos  && 
           s.find("qiandao") == string::npos){
            if(cnt == m) {
                ans = s;
            }
            cnt++;
        }
    }
    cout << ans;
    return 0;
}

L1-079 天梯赛的善良

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int mn = INT_MAX;
    int mx = INT_MIN;
    unordered_map<int,int> cnt;
    for(int i = 0;i < n;i++){
        int x;
        cin >> x;
        cnt[x]++;
        mn = min(mn,x);
        mx = max(mx,x);
    }
    cout << mn << " " << cnt[mn] << "\n";
    cout << mx << " " << cnt[mx] << "\n";
    return 0;
}

L1-080 乘法口诀数列

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
const int N = 15000;
int a[N];
int main(){
    int n;
    cin >> a[1] >> a[2];
    cin >> n;
    int idx = 3;
    int now = 1;
    while(idx <= n){
        int x = a[now] * a[now + 1];
        if(x > 9) {
            a[idx++] = x / 10;
            a[idx++] = x % 10;
        }else{
            a[idx++] = x ;
        }
        now ++;
    }
    for(int i = 1;i <= n;i++){
        if(i > 1) cout << " ";
        cout << a[i];
    }
    return 0;
}

L1-081 今天我要赢

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    cout << "I'm gonna win! Today!\n";
    cout <<"2022-04-23";   
    return 0;
}

L1-082 种钻石

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    cout << a / b;
    return 0;
}

L1-083 谁能进图书馆

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x,y;
    cin >> a >> b >> x >> y;
    if(x < a && y >= b){
        printf("%d-Y %d-Y\n",x,y);
        cout << "qing 2 zhao gu hao 1\n";
    }else if(y < a && x >= b){
        printf("%d-Y %d-Y\n",x,y);
        cout << "qing 1 zhao gu hao 2\n";
    }else if(x >= a && y >= a){
        printf("%d-Y %d-Y\n",x,y);
        cout << "huan ying ru guan\n";
    }else if(x < a && y < a){
        printf("%d-N %d-N\n",x,y);
        cout << "zhang da zai lai ba\n";
    }else{
        if(x >= a){
            cout << x <<"-" <<"Y ";
            cout << y <<"-" <<"N\n";
            cout << 1 << ": huan ying ru guan";
        }else{
            cout << x <<"-" <<"N ";
            cout << y <<"-" <<"Y\n";
            cout << 2 << ": huan ying ru guan";
        }
    }
    return 0;
}

L1-084 拯救外星人

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    long ans = 1;
    for(int l = 2;l <= a + b;l++){
        ans *= l;
    }
    cout << ans;
    return 0;
}

L1-085 试试手气

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
bool vis[6][7];
int main(){

    for(int i = 0;i < 6;i++){
        int x;
        cin >> x;
        vis[i][x] = true;
    }
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 6;j++){
            if(j && i == n - 1 ) cout <<" ";
            for(int k = 6;k >= 1;k--){
                if(!vis[j][k]){
                    vis[j][k] = true;
                    if(i == n - 1 )
                    cout << k;
                    break;
                }
            }
        }
    }
    return 0;
}

L1-086 斯德哥尔摩火车上的题

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
string f(string a){
    string s = "";
    for(int i = 1;i < a.size();i++){
        int x = a [i] - '0',y = a[i - 1] - '0';
        if(x%2 == y %2){
            s += to_string(max(x,y));
        }
    }
    return s;
}
int main(){
    string a,b;
    cin >> a >> b;
    string s = f(a);
    string t = f(b);
    if(s == t){
        cout << s;
    }else{
        cout << s <<"\n" <<t;
    }
    
    return 0;
}

L1-087 机工士姆斯塔迪奥

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,q;
    cin >> n >> m >> q;
    set<int> row;
    set<int> col;
    for(int i = 0;i < q;i++){
        int op,x;
        cin >> op >> x;
        if(op == 0){
            row.insert(x);
        }else{
            col.insert(x);
        }
    }
    //int ans = n * m - m * row.size() - n * col.size() + row.size() * col.size();
    int ans = (n - row.size()) * (m - col.size());
    cout << ans;
    return 0;
}

L1-088 静静的推荐

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int t[300];
int main(){
    int n,k,s;
    cin >> n >> k >> s;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        int tian,pat;
        cin >> tian >> pat;
        if(tian < 175) continue;
        if(pat >= s) ans++;
        else         t[tian]++;
    }
    for(int i = 175;i <= 290;i++){
        ans += min(t[i],k);
    }
    cout << ans;
    return 0;
}

L1-089 最好的文档

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    printf("Good code is its own best documentation.");
    return 0;
}

L1-090 什么是机器学习

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int ans = a + b;
    cout << ans - 16 << "\n";
    cout << ans - 3 << "\n";
    cout << ans - 1 << "\n";
    cout << ans  << "\n";
    return 0;
}

L1-091 程序员买包子

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,m,k;
    string x;
    cin >> n >> x >> m >> k;
    if(k == n){
       cout << "mei you mai "<<x << " de";
    }else if(k == m){
        cout << "kan dao le mai " <<x <<" de";
    }else{
        cout << "wang le zhao mai "<<x<<" de";
    }
    return 0;
}

L1-092 进化论

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    while(n--){
        int a,b,x;
        cin >> a >> b >> x;
        if(a + b == x){
            cout << "Tu Dou\n";
        }else if(a * b == x){
            cout << "Lv Yan\n";
        }else{
            cout << "zhe du shi sha ya!\n";
        }
    }
    return 0;
}

L1-093 猜帽子游戏

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];
    int k;
    cin >> k;
    while(k--){
        bool isRight = false;
        vector<int> b(n);
        for(int i = 0;i < n;i++) cin >> b[i];
        for(int i = 0;i < n;i++){
            int x = b[i];
            if(x == 0) continue;
            if(a[i] == x){
                isRight = true;
            }else{
                isRight = false;
                break;
            }
        }
        if(isRight) cout <<"Da Jiang!!!\n";
        else cout <<"Ai Ya\n";
    }
    return 0;
}

L1-094 剪切粘贴

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n;
    cin >> n;
    while(n--){
        int x,y;
        string s1,s2;
        cin >> x >> y >> s1 >> s2;
        string cut = s.substr(x - 1,y - x + 1);
        s.erase(s.begin() + x - 1,s.begin() + y);
        int len = s1.size();
        s1 = s1 + s2;
        if(s.find(s1) != string::npos){
            int pos = s.find(s1);
            s.insert(pos + len,cut);
        }else{
            s.insert(s.size(),cut);
        }
    }
    cout << s;
    return 0;
}

L1-095 分寝室

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n0,n1,n;
    cin >> n0 >> n1 >> n;
    int mn = 0x3f3f3f3f;
    int f,m;
    for(int i = 1;i < n;i++){
        int j = n - i;
        if(n0 % i == 0 && n1 % j == 0){
            int boy = n0 / i,girl = n1 / j;
            if(boy == 1 || girl == 1) continue; 
            int div = abs(boy - girl);
            if(div < mn){
                mn = div;
                f = i;
                m = j;
            }
        }
    }
    if(mn != 0x3f3f3f3f){
        cout << f << " " << m;
    }else{
        cout << "No Solution";
    }
    return 0;
}

L1-096 谁管谁叫爹

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int f(long long x){
    int sum = 0;
    while(x){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
    int n; 
    cin >> n;
    while(n--){
        long long a,b;
        cin >> a >> b;
        if((a % f(b) == 0) != (b % f(a) == 0)){
            if(a % f(b) == 0) cout <<"A\n";
            else cout << "B\n";
        }else{
            if(a > b)  cout <<"A\n";
            else cout << "B\n";
        }
    }
    return 0;
}

L1-097 编程解决一切

c++ 复制代码
#include<bits/stdc++.h>
using namespace std ;
int main(){
    cout<<"Problem? The Solution: Programming.";
    return 0;
}

L1-098 再进去几个人

c++ 复制代码
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int a,b;cin>>a>>b;
    cout<<b-a;
    return 0;
}

L1-099 帮助色盲

c++ 复制代码
#include<bits/stdc++.h>
using namespace std ;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  int a,b;cin>>a>>b;
  if(a==2)
      cout<<"-\nstop";
    else if(a==1)
        cout<<(b?"-":"dudu")<<"\nmove";
    else
        cout<<(b?"-":"biii")<<"\nstop";


    return 0;
}

L1-100 四项全能

c++ 复制代码
#include<bits/stdc++.h>
using namespace std ;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;cin>>n>>m;
    int sum=0;
    for(int i=0;i<m;i++)
    {
        int x;
        cin >>x;
        sum+=x;
    }
    cout<<max(0,sum-(m-1)*n);
    return 0;
}

L1-101 别再来这么多猫娘了

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    cin.ignore();
    vector<string> s(n);
    for(int i = 0;i < n;i++) getline(cin,s[i]);
    int k;
    cin >> k;
    cin.ignore();
    int cnt = 0;
    string ans;
    getline(cin,ans);
    for(int i = 0;i < n;i++){
        int pos = 0;
        while((pos = ans.find(s[i],pos)) != string::npos){
            ans.erase(pos,s[i].size());
            ans.insert(pos,string(1,1));
            pos++;
            cnt++;
        }
    }
    if(cnt < k){
        for(char c : ans){
            if(c == 1) cout << "<censored>";
            else cout << c;
        }
    }else{
        cout << cnt << "\nHe Xie Ni Quan Jia!";
    }
    return 0;
}

L1-102 兰州牛肉面

c++ 复制代码
#include "bits/stdc++.h"
using namespace std;
const int N=150;
double a[N];
int cnt[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n ;cin>>n;
    for(int i=1;i<=n;i++)    cin>>a[i];
    int pingZhong,num;
    cin>>pingZhong>>num;
    while(pingZhong!=0)
    {
        cnt[pingZhong]+=num;
        cin>>pingZhong>>num;
    }
    double sum=0;
    for(int i=1;i<=n;i++)
    {
        cout<<cnt[i]<<'\n';
        sum+=1.00*a[i]*cnt[i];
    }
    printf("%.2lf",sum);
    return 0;
}

L1-103 整数的持续性

c++ 复制代码
#include "bits/stdc++.h"
using namespace std;
int f(int x)
{
    int sum=1;
    while(x)
    {
        sum*=(x%10);
        x/=10;
    }
    return sum;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b;cin>>a>>b;
    int mx=0;
    vector<int> g[5050];
    for(int i=a;i<=b;i++)
    {
        int cnt=0;
        int x=i;
        while(x>=10)
        {
           cnt++;
            x=f(x);
        }
        if(cnt>=mx)
        {
            mx=cnt;
            g[mx].push_back(i);
        }
    }
    cout<<mx<<"\n";
    for(int i=0;i<(int)g[mx].size();i++)
    {
        cout<<g[mx][i];
        if(i==(int)g[mx].size()-1)continue;
        cout<<" ";
    }
    return 0;
}

L1-104 九宫格

c++ 复制代码
#include "bits/stdc++.h"

using namespace std;

void solve() {
    int n = 9;
    vector a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }

    for (int i = 0; i < n; i += 3) {
        for (int j = 0; j < n; j += 3) {
            vector<int> c(n);

            for (int x = 0; x < 3; x++) {
                for (int y = 0; y < 3; y++) {
                    if (a[i + x][j + y] < 0 || a[i + x][j + y] >= 9) {
                        cout << "0\n";
                        return;
                    }
                    c[a[i + x][j + y]]++;
                }
            }
            if (c != vector<int>(n, 1)) {
                cout << "0\n";
                return;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        vector<int> c(n);

        for (int j = 0; j < n; j++) {
            c[a[i][j]]++;
        }
        if (c != vector<int>(n, 1)) {
            cout << "0\n";
            return;
        }
        
        c.assign(n, 0);
        for (int j = 0; j < n; j++) {
            c[a[j][i]]++;
        }
        if (c != vector<int>(n, 1)) {
            cout << "0\n";
            return;
        }
    }

    cout << "1\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

L1-105 珍惜生命

c++ 复制代码
#include "bits/stdc++.h"
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.";
    return 0;
}

L1-106 偷感好重

c++ 复制代码
#include "bits/stdc++.h"
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    cin >> a >> b >> c;
    cout << a + b + c;
    return 0;
}

L1-107 高温补贴

c++ 复制代码
#include "bits/stdc++.h"
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T,S,t;
    cin >> T >> S >> t;
    if(T > 35 && S == 1 &&  t >= 33){
        cout << "Bu Tie\n";
        cout << T;
    }else if(S == 0 && !(T > 35 &&   t >= 33 ) ){
        cout << "Shu Shi\n";
        cout << t;
    }else if(S == 0 ){
        cout << "Shi Nei\n";
        cout << T;
    }else if(!(T > 35 &&   t >= 33 )){
        cout << "Bu Re\n";
        cout << t;
    }
    return 0;
}

L1-108 零头就抹了吧

c++ 复制代码
#include "bits/stdc++.h"
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int  n;
    cin >> n;
    int ans  = 1;
    while(ans < n){
        ans <<= 1;
    }
    cout << (ans == n ? n : ans >> 1);
    return 0;
}

L1-109 这是字符串题

c++ 复制代码
#include "bits/stdc++.h"
using namespace std;
int cnt[26];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s ;
    cin >> s;
    for(char c : s){
        cnt[c - 'a'] ++;
    }
    int ans  = 0;
    for(int i = 0;i < 26;i++){
        int x;
        cin >> x;
        ans += x * cnt[i];
    }
    for(int i = 0;i < 26;i++){
        if(i) cout << " ";
        cout << cnt[i];
    }
    cout << "\n" << ans;
    return 0;
}

L1-110 这不是字符串题

看数据范围输出的正整数1~26 ,可以转化为字符串方便操作

c++ 复制代码
//带空格
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    string a = " ";
    cin >> n >> m;
    for(int i = 0; i < n;i++){
        int x;
        cin >> x;
        a += (char)(x - 1 + 'a');
    }
    while(m--){
        int opt;
        cin >> opt;
        if(opt == 1){
            int L1,L2,x;
            string s1 = "",s2 = "";
            cin >> L1;
            for(int i = 0;i < L1;i++){
                cin >> x;
                s1 += (char)(x - 1 + 'a');
            }
            cin >> L2;
            for(int i = 0;i < L2;i++){
                cin >> x;
                s2 += (char)(x - 1 + 'a');
            }
            if(a.find(s1) != string::npos){
                int pos = a.find(s1);
                a.erase(a.begin() + pos,a.begin() + pos + L1);
                a.insert(pos,s2);
            }
        }else if(opt == 2){
            string b = a;
            int pos = 1;
            for(int i = 1;i < b.size() - 1;i++){
                if((b[i] & 1) == (b[i + 1] & 1)){
                    a.insert(i + pos,string(1,(b[i] + b[i + 1]) / 2));
                    pos++;
                }
            }
        }else{
            int l,r;
            cin >> l >> r;
            reverse(a.begin() + l,a.begin() + r + 1);
        }
        // for(int i = 1;i < a.size();i++){
        //     if(i != 1) cout << " ";
        //     cout << (a[i] - 'a' + 1);
        // }
        // cout << "\n";
    }
    //cout << a;
    for(int i = 1;i < a.size();i++){
        if(i != 1) cout << " ";
        cout << (a[i] - 'a' + 1);
    }
    cout << "\n";
    return 0;
}   
c++ 复制代码
//不带空格
#include<bits/stdc++.h>
using  namespace std;
int main()
{
	int  n,m;
	cin>>n>>m;
	string s="";
	for(int i = 0;i < n;i++)
	{
		int x;
		cin >> x;
		s +=(char)(x-1+'a');
	}
	//cout<<s<<"\n";
	for(int i=0;i<m;i++)
	{
		int opt;    cin>>opt;
		if(opt==1)
		{
			int l1,l2;
			cin>>l1;
			string t1="";
			for(int j=0;j<l1;j++)
			{
				int x;cin>>x;
				t1+=(char)(x-1+'a');
			}    
			cin>>l2;
			string t2="";
			for(int j=0;j<l2;j++)
			{
				int x;cin>>x;
				t2+=(char)(x-1+'a');
			}
			size_t idx=s.find(t1);
			if(idx!=string::npos)
			{
				s.replace(idx,l1,t2);
			}
//			cout<<(int)(s[0]-'a'+1);
//			for(int i = 1;i<s.size();i++)
//			{
//				cout<<" "<<(int)(s[i]-'a'+1);
//			}
//			cout<<"\n";
		}
		else if(opt==2)
		{
			string temp="";
			for(int j=0;j<s.size()-1;j++)
			{
				temp+=s[j];
				int x=s[j]-'a'+1+s[j+1]-'a'+1;
				if(x%2==0)
				{
					temp+=(char)(x/2-1+'a');
				}
			}
			temp+=s.back();
			s=temp;
//			cout<<(int)(s[0]-'a'+1);
//			for(int i = 1;i<s.size();i++)
//			{
//				cout<<" "<<(int)(s[i]-'a'+1);
//			}
//			cout<<"\n";
		}
		else 
		{
			int l,r;
			cin>>l>>r;
			reverse(s.begin()+l-1,s.begin()+r);
//			cout<<(int)(s[0]-'a'+1);
//			for(int i = 1;i<s.size();i++)
//			{
//				cout<<" "<<(int)(s[i]-'a'+1);
//			}
//			cout<<"\n";
		}
	}
	//cout<<s<<endl;
	cout<<(int)(s[0]-'a'+1);
	for(int i = 1;i<s.size();i++)
	{
		cout<<" "<<(int)(s[i]-'a'+1);
	}
	return 0;
}

L1-111 大幂数

c++ 复制代码
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long  n;
    cin >> n;
    bool check = false;
    for(int k = 31;k >= 1;k--){
        long long sum = 0;
        int i = 1;
        while(sum < n){
            sum += pow(i,k);
            i++;
        }
        if(sum == n){
            check = true;
            for(int j = 1;j < i;j++){
                if(j != 1) cout << "+";
                cout << j << "^" << k;
            }
            break;
        }
    }
    if(!check) {
        cout << "Impossible for " << n << ".";
    }
    return 0;
}

L1-112 现代战争

c++ 复制代码
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
using namespace std;
typedef tuple<int,int,int> tp;
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> g(n,vector<int>(m));
    priority_queue<tp> q;
    for(int i = 0; i < n; i++)
        for(int j = 0 ;j < m ;j++)    
        {
            cin>>g[i][j];
            q.push({g[i][j],i,j});
        }
    vector<int> col(n),row(m);
    while(k--)
    {
        auto [v,x,y] = q.top();
        q.pop();
        while(col[x] || row[y])
        {
            auto[vv,x1,y1]=q.top();
            q.pop();
            x = x1;
            y = y1;
        }
        col[x] = true;
        row[y] = true;
    }
    for(int i = 0;i < n ;i++)
    {
        if(col[i])    continue;
        int first = 1;
        for(int  j = 0; j < m;j++)
        {
            if(row[j])    continue;
           if(first) cout<<g[i][j];
            else   cout<<" "<<g[i][j];
            first = 0;
        }
        cout<<"\n";
    }
    return 0;
}