跳转至

Lzh's Contest 题解

题目链接

题解

A

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
int n;int a[129];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        char t;
        cin>>t;
        a[t]++;
    }
    for(int i=0;i<129;i++){
        if(a[i]!=0){
            cout<<(char)i<<":"<<a[i]<<endl;
        }
    }
    return 0;
}

B

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
string a,ans;
int main(void){
    cin>>a;
    for(int i=0;i<a.size();i++){
        ans+=(a[i]-'0'+65);
    }
    cin>>a;
    for(int i=0;i<a.size();i++){
        ans+=(a[i]-'0'+65);
    }
    cin>>a;ans+=a;
    cin>>a;
    for(int i=0;i<a.size();i++){
        if(a[i]<='9'&&a[i]>='0'){
            if((a[i]-'0')<ans.size()){
                ans[a[i]-'0']+=1;
            }
        }
    } 
    int i=0;
    while(ans[i]!='\0'){
        if(97<=ans[i]&&ans[i]<=122){
            ans[i]=ans[i]-32;
        }
        i++;
    }
    cout<<ans;
    return 0;
} 

C

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include<stdio.h>
#include<string>
#include<string.h>
#include<iostream>
using namespace std;
int compare(string str1,string str2) {
    if(str1.length()>str2.length()) return 1;
    else if(str1.length()<str2.length())  return -1;
    else return str1.compare(str2);
}
string add(string str1,string str2) {
    string str;
    int len1=str1.length();
    int len2=str2.length();
    if(len1<len2) {
        for(int i=1; i<=len2-len1; i++)
            str1="0"+str1;
    } else {
        for(int i=1; i<=len1-len2; i++)
            str2="0"+str2;
    }
    len1=str1.length();
    int cf=0;
    int temp;
    for(int i=len1-1; i>=0; i--) {
        temp=str1[i]-'0'+str2[i]-'0'+cf;
        cf=temp/10;
        temp%=10;
        str=char(temp+'0')+str;
    }
    if(cf!=0)  str=char(cf+'0')+str;
    return str;
}

string sub(string str1,string str2) {
    string str;
    int tmp=str1.length()-str2.length();
    int cf=0;
    for(int i=str2.length()-1; i>=0; i--) {
        if(str1[tmp+i]<str2[i]+cf) {
            str=char(str1[tmp+i]-str2[i]-cf+'0'+10)+str;
            cf=1;
        } else {
            str=char(str1[tmp+i]-str2[i]-cf+'0')+str;
            cf=0;
        }
    }
    for(int i=tmp-1; i>=0; i--) {
        if(str1[i]-cf>='0') {
            str=char(str1[i]-cf)+str;
            cf=0;
        } else {
            str=char(str1[i]-cf+10)+str;
            cf=1;
        }
    }
    str.erase(0,str.find_first_not_of('0'));
    return str;
}
string mul(string str1,string str2) {
    string str;
    int len1=str1.length();
    int len2=str2.length();
    string tempstr;
    for(int i=len2-1; i>=0; i--) {
        tempstr="";
        int temp=str2[i]-'0';
        int t=0;
        int cf=0;
        if(temp!=0) {
            for(int j=1; j<=len2-1-i; j++)
                tempstr+="0";
            for(int j=len1-1; j>=0; j--) {
                t=(temp*(str1[j]-'0')+cf)%10;
                cf=(temp*(str1[j]-'0')+cf)/10;
                tempstr=char(t+'0')+tempstr;
            }
            if(cf!=0) tempstr=char(cf+'0')+tempstr;
        }
        str=add(str,tempstr);
    }
    str.erase(0,str.find_first_not_of('0'));
    return str;
}

int main() {
    char ops;cin>>ops;
    string str1,str2;
    cin>>str1>>str2;
    switch(ops){
        case '+':
            cout<<add(str1,str2)<<endl;
            break;
        case '-':
            cout<<sub(str1,str2)<<endl;
            break;
        case '*':
            cout<<mul(str1,str2)<<endl;
            break;
    }
    return 0;
}

D

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main(void){
    char a[99];
    cin>>a;
    int i=0;
    while(a[i]!='\0'){
        if(97<=a[i]&&a[i]<=122){
            a[i]=a[i]-32;
        }
        i++;
    }
    cout<<a;
    return 0;
}