11111111

目录

注水问题

数字之中有9吗

求绝对值

求面积的问题

四位数中有偶数位么

包裹托运

乘车费用

彩票

三角形形状

回文数

生肖

昨日和明天

日期合法性

石头剪刀布

时间转换器

线段包含

招聘

考试结束时间

圆环面积

高利贷

n个数的平均值

n个数的最小值

计算复利2

n个数的极差

n个数的乘法

输出乘法表

11的倍数

X天后的日期

n以内7的倍数

字母三角形

输出A字三角形

输出A字菱形

输出字母菱形

输出字母沙漏

五位质数回文数

数字游戏

字符串中A的数量

最长的名字

字符串

大数的奇偶判断

字符反转

最后一个单词

矩阵旋转

双手石头剪刀布

三天后是星期几

某天是星期几

N阶递减三角形

数列计算1

数列计算

打印图形

打印图形2

打印图形3

特殊体的表面积

高利贷2

π

余弦公式

艾斯的农场

勾股定理

字符串操作1

字符串操作2

规范化名字

密码翻译

禁止吸烟

排列名单

统计字符个数

批量替换字符串

成绩统计

寻找字符串

字母图形

对称字符串

二分法求方程近似解

幂级数

大小写翻转

最大的数


计算复利

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int n;
    cin >> n;
    double m = 0;
    m = (m + n) * 1.00417;
    m = (m + n) * 1.00417;
    m = (m + n) * 1.00417;
    m = (m + n) * 1.00417;
    m = (m + n) * 1.00417;
    m = (m + n) * 1.00417;
    printf("$%.2f\n", m);
    return 0;
}
注水问题
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int a, b, c, t;
    cin >> a >> b >> c >> t;
    double a1 = 1.0 / a, b1 = 1.0 / b, c1 = 1.0 / c;
    double w = (a1 + b1) * t;
    double t2 = (1 - w) / (a1 + b1 - c1);
    printf("%.2f\n", t + t2);
    return 0;
}

数字之中有9吗

#include <iostream>
using namespace std;

int main() {
    int a;
    cin >> a;
    if (a % 10 == 9 || a /10 % 10 == 9 || a / 100 == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

求绝对值

#include <iostream>
using namespace std;

int main() {
    double n;
    cin >> n;
    if (n >= 0) {
        cout << n << endl;
    } else {
        cout << -n << endl;
    }
    return 0;
}
求面积的问题
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    char x;
    cin >> x;
    double m, n;
    cin >> m >> n;
    if (x == 'r') {
        printf("%.2f\n", m * n);
    } else {
        printf("%.2f\n", m * n / 2);
    }
    return 0;
}

四位数中有偶数位么

#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n % 10 % 2 == 0 || n / 10 % 10 % 2 == 0 ||
        n / 100 % 10 % 2 == 0 || n / 1000 % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}
包裹托运
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    double x;
    cin >> x;
    if (x <= 15) {
        printf("%.2f\n", x * 6);
    } else {
        printf("%.2f\n", 15 * 6 + (x - 15) * 9);
    }
    return 0;
}
乘车费用
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n <= 3) {
        cout << 13 + 1 << endl;
    } else {
        cout << 13 + (n - 3) * 2.3 + 1 << endl;
    }
    return 0;
}

彩票
#include <iostream>
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    if (x == y) {
        cout << 100 << endl;
    } else if (x / 10 == y % 10 && x % 10 == y / 10) {
        cout << 20 << endl;
    } else if (x / 10 == y % 10 || x / 10 == y / 10 ||
        x % 10 == y % 10 || x % 10 == y / 10) {
        cout << 2 << endl;    
    } else {
        cout << 0 << endl;
    }
    return 0;
}
三角形形状
#include <iostream>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) {
        int t = a;
        a = b;
        b = t;
    }
    if (b > c) {
        int t = b;
        b = c;
        c = t;
    }
    if (a + b > c) {
        if (a * a + b * b == c * c) {
            cout << "right triangle" << endl;
        } else if (a * a + b * b > c * c) {
            cout << "acute triangle" << endl;
        } else {
            cout << "obtuse triangle" << endl;
        }
    } else {
        cout << "illegal triangle" << endl;
    }
    return 0;
}
回文数
#include <iostream>
using namespace std;

int main() {
    int a;
    cin >> a;
    if (a / 1000 > 0) {
        if (a / 1000 == a % 10 && a / 100 % 10 == a / 10 % 10) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } else if (a / 100 > 0) {
        if (a / 100 == a % 10) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } else if (a / 10 > 0) {
        if (a / 10 == a % 10) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } else {
        cout << "YES" << endl;
    }
    return 0;
}
生肖
#include <iostream>
using namespace std;

int main() {
    int y;
    cin >> y;
    y += 2400;
    int t = (y - 1900) % 12;
    switch (t) {
        case 0 : cout << "rat" << endl; break;
        case 1 : cout << "ox" << endl; break;
        case 2 : cout << "tiger" << endl; break;
        case 3 : cout << "rabbit" << endl; break;
        case 4 : cout << "dragon" << endl; break;
        case 5 : cout << "snake" << endl; break;
        case 6 : cout << "horse" << endl; break;
        case 7 : cout << "sheep" << endl; break;
        case 8 : cout << "monkey" << endl; break;
        case 9 : cout << "rooster" << endl; break;
        case 10 : cout << "dog" << endl; break;
        case 11 : cout << "pig" << endl; break;
    }
    return 0;
}
昨日和明天
#include <iostream>
using namespace std;

int day_month(int y, int m) {
    switch(m) {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10 :
        case 12 : return 31;
        case 4 :
        case 6 :
        case 9 :
        case 11 : return 30;
    }
    if (y % 400 == 0 || y % 100 != 0 && y % 4 == 0) {
        return 29
    } else {
        return 28;
    }
}

int main() {
    int y, m, d;
    cin >> y >> m >> d;
    if (m == 1 && d == 1) {
        cout << y - 1 << " 12 31" << endl;
        cout << y << " 1 2" << endl;
    } else if (m == 12 && d == 31) {
        cout << y << " 12 30" << endl;
        cout << y + 1 << " 1 1" << endl;
    } else if (d == day_month(y, m)) {
        cout << y << " " << m << " " << d - 1 << endl;
        cout << y << " " << m + 1 << " " << 1 << endl;
    } else if (d == 1) {
        cout << y << " " << m - 1 << " " << day_month(y, m - 1) << endl;
        cout << y << " " << m << " " << 2 << endl;
    } else {
        cout << y << " " << m << " " << d - 1 << endl;
        cout << y << " " << m << " " << d + 1 << endl;
    }
    return 0;
}
日期合法性
#include <iostream>
using namespace std;

int day_month(int y, int m) {
    switch (m) {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10 :
        case 12 : return 31;
        case 4 :
        case 6 :
        case 9 :
        case 11 : return 30;
    }
    if (y % 400 == 0 || y % 100 != 0 && y % 4 == 0) {
        return 29;
    } else {
        return 28;
    }
}

int main() {
    int y, m, d;
    cin >> y >> m >> d;
    if (m < 1 || m > 12) {
        cout << "NO" << endl;
    } else if (d < 1 || d > day_month(y, m)) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}
石头剪刀布
#include <iostream>
using namespace std;

int main() {
    char a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "TIE" << endl;
    } else if (a == 'O' && b == 'Y' ||
               a == 'Y' && b == 'H' ||
               a == 'H' && b == 'O') {
        cout << "MING" << endl;           
    } else {
        cout << "LI" << endl;
    }
    return 0;
}
时间转换器
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int t;
    cin >> t;
    if (t < 43200) {
        printf("%02d:%02d:%02d am\n", t / 3600, t % 3600 / 60, t % 60);
    } else if (t < 43200 + 3600) {
        printf("%02d:%02d:%02d midnoon\n", t / 3600, t % 3600 / 60, t % 60);
    } else {
        t -= 43200;
        printf("%02d:%02d:%02d pm\n", t / 3600, t % 3600 / 60, t % 60);
    }
    return 0;
}
线段包含
#include <iostream>
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a >= c && b <= d) {
        cout << "YES" << endl;
    } else if (c >= a && d <= b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}
招聘
#include <iostream>
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((a > 0 || b <= 50) && (c <= 25 || d >= 5)) {
        cout << "ok" << endl;
    } else {
        cout << "pass" << endl;
    }
    return 0;
}
考试结束时间
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int h, m, s, t;
    cin >> h >> m >> s >> t;
    int t2 = h * 3600 + m * 60 + s + t;
    if (t2 >= 86400) {
        t2 -= 86400;
    }
    if (t2 < 43200) {
        if (t2 < 3600) {
            t2 += 43200;
        }
        cout << t2 / 3600 << ":" << t2 % 3600 / 60 << ":" << t2 % 60 << "am" << endl;
    } else {
        t2 -= 43200;
        if (t2 < 3600) {
            t2 += 43200;
        }
        cout << t2 / 3600 << ":" << t2 % 3600 / 60 << ":" << t2 % 60 << "pm" << endl;
    }
    printf("%.2f%%\n", t / 86400.0 * 100);
    return 0;
}
圆环面积
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    double r1, r2;
    cin >> r1 >> r2;
    printf("%.2f\n", 3.14 * r1 * r1 - 3.14 * r2 * r2);
    return 0;
}
高利贷
#include <iostream>
using namespace std;

int main() {
    int x, n;
    cin >> x >> n;
    double m = x;
    for (int i = 0; i < n; i++) {
        m = m * 1.06;
    }
    cout << (int)m << endl;
    return 0;
}
n个数的平均值
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int sum = 0, n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        sum += temp;
    }
    printf("%.2f\n", 1.0 * sum / n);
    return 0;
}
n个数的最小值
#include <iostream>
using namespace std;

int main() {
    int n, mmin;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        if (i == 0) {
            mmin = temp;
        } else if (temp < mmin) {
            mmin = temp;
        }
    }
    cout << mmin << endl;
    return 0;
}
计算复利2
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int m, n;
    cin >> m >> n;
    double ans = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + m) * 1.00417;
    }
    printf("$%.2f\n", ans);
    return 0;
}
n个数的极差
#include <iostream>
using namespace std;

int main() {
    int n, mmax, mmin;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        if (i == 0) {
            mmax = mmin = temp;
        }
        if (temp > mmax) {
            mmax = temp;
        }
        if (temp < mmin) {
            mmin = temp;
        }
    }
    cout << mmax - mmin << endl;
    return 0;
}
n个数的乘法
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long ans = 1;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        ans *= temp;
    }
    cout << ans << endl;
    return 0;
}
输出乘法表
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            if (j != i) {
                cout << "\t";
            }
            cout << i << "*" << j << "=" << i*j;
        }
        cout << endl;
    }
    return 0;
}
11的倍数
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int flag = 0;
    for (int i = a; i <= b; i++) {
        if (i % 11 == 0) {
            if (flag == 1) {
                cout << " ";
            }
            cout << i;
            flag = 1;
        }
    }
    return 0;
}
X天后的日期
#include <iostream>
using namespace std;

int day_month(int y, int m) {
    switch (m) {
        case 1 :
        case 3 :
        case 5 :
        case 7 :
        case 8 :
        case 10 :
        case 12 : return 31;
        case 4 :
        case 6 :
        case 9 :
        case 11 : return 30;
    }
    if (y % 400 == 0 || y % 100 != 0 && y % 4 == 0) {
        return 29;
    } else {
        return 28;
    }
}

int main() {
    int x, y, m, d;
    cin >> x >> y >> m >> d;
    d += x;
    while (d > day_month(y, m)) {
        d -= day_month(y, m);
        m++;
        if (m == 13) {
            m = 1;
            y++;
        }
    }
    cout << y << " " << m << " " << d << endl;
    return 0;
}
n以内7的倍数
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 7; i <= n; i += 7) {
        cout << i << endl;
    }
    return 0;
}
字母三角形
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    char a = 'A';
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            cout << a;
            a++;
        }
        cout << endl;
    }
    return 0;
}
输出A字三角形
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < (n - i) * 2; j++) {
            cout << "A";
        }
        cout << endl;
    }
    return 0;
}
输出A字菱形
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < (n - i); j++) {
            cout << " ";
        }
        for (int j = 0; j < 2 * i; j++) {
            cout << "A";
        }
        cout << endl;
    }
    for (int i = n - 1; i > 0; i--) {
        for (int j = 0; j < (n - i); j++) {
            cout << " ";
        }
        for (int j = 0; j < 2 * i; j++) {
            cout << "A";
        }
        cout << endl;
    }
    return 0;
}
输出字母菱形
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < (n - i); j++) {
            cout << " ";
        }
        for (int j = 0; j < 2 * i - 1; j++) {
            cout << (char)('A' + i - 1);
        }
        cout << endl;
    }
    for (int i = n - 1; i > 0; i--) {
        for (int j = 0; j < (n - i); j++) {
            cout << " ";
        }
        for (int j = 0; j < 2 * i - 1; j++) {
            cout << (char)('A' + i - 1);
        }
        cout << endl;
    }
    return 0;
}
输出字母沙漏
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            cout << " ";
        }
        for (int j = i; j <= n; j++) {
            cout << (char)('A' + j);
        }
        for (int j = n - 1; j >= i; j--) {
            cout << (char)('A' + j);
        }
        cout << endl;
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < i; j++) {
            cout << " ";
        }
        for (int j = i; j <= n; j++) {
            cout << (char)('A' + j);
        }
        for (int j = n - 1; j >= i; j--) {
            cout << (char)('A' + j);
        }
        cout << endl;
    }
    return 0;
}
五位质数回文数
#include <iostream>
using namespace std;

int is_prime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

int is_back(int n) {
    if (n / 10000 == n % 10 && n / 1000 % 10 == n / 10 % 10) {
        return 1;
    } else {
        return 0;
    }
} 

int main() {
    int a, b;
    cin >> a >> b;
    int flag = 0;
    for (int i = a; i <= b; i++) {
        if (is_prime(i) && is_back(i)) {
            if (flag == 1) {
                cout << " ";
            }
            cout << i;
            flag = 1;
        }
    }
    return 0;
}
数字游戏
#include <iostream>
using namespace std;

int is_prime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

int is_back(int n) {
    if (n / 10000 == n % 10 && n / 1000 % 10 == n / 10 % 10) {
        return 1;
    } else {
        return 0;
    }
} 

int main() {
    int a, b;
    cin >> a >> b;
    int flag = 0;
    for (int i = a; i <= b; i++) {
        if (is_prime(i) && is_back(i)) {
            if (flag == 1) {
                cout << " ";
            }
            cout << i;
            flag = 1;
        }
    }
    return 0;
}
字符串中A的数量
#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    cin >> str;
    int ans = 0;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'A') {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
最长的名字
#include <iostream>
#include <string>
using namespace std;

int main() {
    string ans;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string temp;
        cin >> temp;
        if (temp.size() > ans.size()) {
            ans = temp;
        }
    }
    cout << ans << endl;
    return 0;
}
字符串
#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    cin >> str;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] >= 'a' && str[i] < 'z' ||
            str[i] >= 'A' && str[i] < 'Z') {
            str[i]++;   
        } else if (str[i] == 'z') {
            str[i] = 'a';
        } else if (str[i] == 'Z') {
            str[i] = 'A';
        }
    }
    cout << str << endl;
    return 0;
}
大数的奇偶判断
#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    cin >> str;
    if ((str[str.size() - 1] - '0' ) % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}
字符反转
#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    cin >> str;
    for (int i = str.size() - 1; i >= 0; i--) {
        cout << str[i];
    }
    cout << endl;
    return 0;
}
最后一个单词
#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    while (cin >> str) {
        
    }
    cout << str.size() << endl;
    return 0;
矩阵旋转
#include <iostream>
using namespace std;

int main() {
    int n, m, num[205][205];
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> num[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = n - 1; j >= 0; j--) {
            if (j != n - 1) {
                cout << " ";
            }
            cout << num[j][i];
        }
        cout << endl;
    }
    return 0;
}
双手石头剪刀布
#include <iostream>
using namespace std;

int check(char a, char b) {
    if (a == b) return 0;
    if (a == 'Y' && b == 'H' ||
        a == 'O' && b == 'Y' ||
        a == 'H' && b == 'O') {
        return 1;    
    }
    return 2;
}

int main() {
    char ml, mr, ll, lr;
    cin >> ml >> mr >> ll >> lr;
    if (check(ml, ll) == 1) {
        if (check(ml, lr) != 2) {
            cout << "MING" << endl;
            return 0;
        } 
        if (check(mr, lr) == 1) {
            cout << "MING" << endl;
            return 0;
        } else {
            cout << "LIHUA" << endl;
            return 0;
        }
    } else if (check(ml, ll) == 0) {
        if (check(mr, lr) == 1) {
            cout << "MING" << endl;
            return 0;
        } else if (check(mr, lr) == 2) {
            cout << "LIHUA" << endl;
            return 0;
        } else {
            cout << "TIE" << endl;
            return 0;
        }
    } else {
        if (check(mr, ll) != 1) {
            cout << "LIHUA" << endl;
            return 0;
        }
        if (check(mr, lr) != 2) {
            cout << "MING" << endl;
            return 0;
        } else {
            cout << "LIHUA" << endl;
            return 0;
        }
    }
    return 0;
}
三天后是星期几
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    n += 3;
    n %= 7;
    switch (n) {
        case 1 :
            cout << "Monday" << endl;
            break;
        case 2 :
            cout << "Tuesday" << endl;
            break;
        case 3 :
            cout << "Wednesday" << endl;
            break;
        case 4 :
            cout << "Thursday" << endl;
            break;
        case 5 :
            cout << "Friday" << endl;
            break;
        case 6 :
            cout << "Saturday" << endl;
            break;
        case 0 :
            cout << "Sunday" << endl;
    }
    return 0;
}
某天是星期几
#include <iostream>
using namespace std;

int main() {
    int y, m, d;
    cin >> y >> m >> d;
    if (m <= 2) {
        m += 12;
        y--;
    }
    int h = (d + 26 * (m + 1) / 10 + y % 100 + y % 100 / 4 + y / 100 / 4 + 5 * (y / 100)) % 7;
    switch (h) {
        case 0 : cout << 6 << endl; break;
        case 1 : cout << 7 << endl; break;
        case 2 : cout << 1 << endl; break;
        case 3 : cout << 2 << endl; break;
        case 4 : cout << 3 << endl; break;
        case 5 : cout << 4 << endl; break;
        case 6 : cout << 5 << endl; break;
    }
    return 0;
}
N阶递减三角形
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = n - i + 1; j > 0; j--) {
            cout << j;
            if (j != 1) {
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}
数列计算1
#include <iostream>
using namespace std;

int main() {
    int n, num[35] = {0, 3}, two = 2, sum = 3;
    cin >> n;
    cout << 3 << endl;
    for (int i = 2; i <= n; i++) {
        num[i] = num[i - 1] + two;
        two += 2;
        sum += num[i];
        cout << num[i] << endl;
    }
    cout << sum << endl;
    return 0;
}
数列计算
#include <iostream>
using namespace std;

int is_prime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

int is_power(int n) {
    switch (n) {
        case 1 :
        case 4 :
        case 9 :
        case 16 :
        case 25 :
        case 36 :
        case 49 :
        case 64 :
        case 81 : return 1;
    }
    return 0;
}

int main() {
    int a, b;
    cin >> a >> b;
    int flag = 0, cnt = 0;
    for (int i = a; i <= b; i++) {
        int ab = i / 1000 * 10 + i / 100 % 10;
        int cd = i / 10 % 10 * 10 + i % 10;
        if (is_prime(i) && is_power(ab) && is_power(cd)) {
            if (flag == 1) {
                cout << " ";
            }
            cout << i;
            flag = 1;
            cnt++;
        }
    }
    cout << endl << cnt << endl;
    return 0;
}
打印图形
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            cout << " ";
        }
        for (int j = i; j < n; j++) {
            cout << (char)('A' + j);
        }
        for (int j = n - 2; j >= i; j--) {
            cout << (char)('A' + j);
        }
        cout << endl;
    }
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j < i; j++) {
            cout << " ";
        }
        for (int j = i; j < n; j++) {
            cout << (char)('A' + j);
        }
        for (int j = n - 2; j >= i; j--) {
            cout << (char)('A' + j);
        }
        cout << endl;
    }
    return 0;
}
打印图形2
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            cout << " ";
        }
        cout << (n - i);
        for (int j = 0; j < 2 * (n - i) - 1; j++) {
            cout << " ";
        }
        cout << (n - i) << endl;
    }
    for (int i = 0; i < n; i++) {
        cout << " ";
    }
    cout << 0 << endl;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < i; j++) {
            cout << " ";
        }
        cout << (n - i);
        for (int j = 0; j < 2 * (n - i) - 1; j++) {
            cout << " ";
        }
        cout << (n - i) << endl;
    }
    return 0;
}
打印图形3
#include <iostream>
using namespace std;

int main() {
    char l;
    cin >> l;
    int n = (int)(l - 'A') + 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            cout << " ";
        }
        for (int j = (n - i - 1); j >= 0; j--) {
            cout << (char)('A' + j);
        }
        for (int j = 0; j < (n - i - 1); j++) {
            cout << (char)('A' + j);
        }
        cout << endl;
    }
    return 0;
}
特殊体的表面积
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    double r, h;
    cin >> r >> h;
    double ans = 3.14 * r * r;
    ans += 2 * r * 2 * r;
    ans += 3.14 * r * h;
    ans += 2 * r * h;
    ans += sqrt(2 * r * 2 * r * 2) * h;
    printf("%.2f\n", ans);
    return 0;
}
高利贷2
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    int x, n;
    cin >> x >> n;
    printf("%.6f\n", x * pow(1.06, n));
    return 0;
}
π
#include <cstdio>
#include <cmath>

int main() {
    printf("%.15f\n", acos(-1));
    return 0;
}
余弦公式
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
    double a, b, t;
    cin >> a >> b >> t;
    double c = sqrt(a * a + b * b - 2 * a * b * cos(t * acos(-1) / 180));
    printf("%.6f\n", c);
    return 0;
}
艾斯的农场
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    cout << ceil((double)n / m) << endl;
    return 0;
}
勾股定理
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    long long c;
    cin >> c;
    int ans = 0;
    for (long long a = 1; a < c; a++) {
        long long b = sqrt(c * c - a * a);
        if (a * a + b * b == c * c) {
            ans++;
        }
    }
    cout << ans / 2 << endl;
    return 0;
}
字符串操作1
#include <iostream>
#include <string>
using namespace std;

int main() {
    string a, b;
    int n;
    cin >> a >> n >> b;
    if (a.size() > 100) {
        cout << 100 << endl;
    } else {
        cout << a.size() << endl;
    }
    a = a.insert(n - 1, b);
    cout << a << endl;
    for (int i = a.size() - 1, j = 1; i >= 0; i--, j++) {
        if (a[i] == 'x') {
            cout << j << endl;
            break;
        }
    }
    return 0;
}
字符串操作2
#include <iostream>
#include <string>
using namespace std;

int main() {
    string a, b;
    int n;
    cin >> a >> n >> b;
    cout << a.size() << endl;
    cout << a.find("a") + 1 << endl;
    a = a.insert(n - 1, b);
    cout << a << endl;
    return 0;
}
规范化名字
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int n;
    string a[105];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i][0] >= 'a' && a[i][0] <= 'z') {
            a[i][0] -= 'a' - 'A';
        }
        for (int j = 1; j < a[i].size(); j++) {
            if (a[i][j] >= 'A' && a[i][j] <= 'Z') {
                a[i][j] += 'a' - 'A';
            }
        }
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        cout << a[i] << endl;
    }
    return 0;
}
密码翻译
#include <iostream>
#include <string>
using namespace std;

int main() {
    int n, num[128] = {0};
    cin >> n;
    for (int i = 0; i < n; i++) {
        char a;
        int b;
        cin >> a >> b;
        num[(int)a] = b;
    }
    string str;
    cin >> str;
    int ans = 0;
    for (int i = 0; i < str.size(); i++) {
        ans += num[(int)str[i]];
    }
    cout << ans << endl;
    return 0;
}
禁止吸烟
#include <iostream>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        while (str.find("Ban_smoking") != -1) {
            int pos = str.find("Ban_smoking");
            str.replace(pos, 11, "No_smoking");
        }
        cout << str << endl;
    }
    return 0;
}
排列名单
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string s[10];
    for (int i = 0; i < 10; i++) {
        cin >> s[i];
    }
    sort(s, s + 10);
    for (int i = 0; i < 10; i++) {
        cout << s[i] << endl;
    }
    return 0;
}
统计字符个数
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    char s[10005] = {0};
    gets(s);
    int let = 0, num = 0, spa = 0, oth = 0;
    for (int i = 0; s[i] != 0; i++) {
        if (s[i] >= 'a' && s[i] <= 'z' ||
            s[i] >= 'A' && s[i] <= 'Z') {
            let++;    
        } else if (s[i] >= '0' && s[i] <= '9') {
            num++;
        } else if (s[i] == ' ') {
            spa++;
        } else {
            oth++;
        }
    }
    cout << let << " " << num << " " << spa << " " << oth << endl;
    return 0;
}
批量替换字符串
#include <iostream>
#include <cstdio>
using namespace std;

char s[1000005] = {0};
char a[3000005] = {0};

int main() {
    gets(s);
    for (int i = 0, j = 0; s[i]; i++) {
        if (s[i] != ' ') {
            a[j] = s[i];
            j++;
        } else {
            a[j] = '%';
            a[j + 1] = '2';
            a[j + 2] = '0';
            j += 3;
        }
    }
    cout << a << endl;
    return 0;
}
成绩统计
#include <iostream>
using namespace std;

int main() {
    int n, y = 0, l = 0, z = 0, c = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (t >= 90) {
            y++;
        } else if (t >= 80) {
            l++;
        } else if (t >= 60) {
            z++;
        } else {
            c++;
        }
    }
    cout << "You " << y << endl;
    cout << "Liang " << l << endl;
    cout << "Zhong " << z << endl;
    cout << "Cha " << c << endl;
    return 0;
}
寻找字符串
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    char s1[1005], s2[1005];
    gets(s1);
    gets(s2);
    int ans = 0;
    int l1 = strlen(s1), l2 = strlen(s2);
    for (int i = 0; i <= l1 - l2; i++) {
        if (strncmp(s2, &s1[i], l2) == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
字母图形
#include <iostream>
#include <cstring>
using namespace std;

int main() {
    char s[30];
    cin >> s;
    int a = 0;
    int l = strlen(s);
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < l; j++) {
            cout << s[a];
            a++;
            a %= l;
        }
        cout << endl;
        a += l - 2;
        a %= l;
    }
    return 0;
}
对称字符串
#include <iostream>
#include <cstring>
using namespace std;

char s[5000000] = {'A'};

int main() {
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        int l = strlen(s);
        for (int j = 0; j < l; j++) {
            s[2 * l - j] = s[j];
        }
        s[l] = 'A' + i;
    }
    cout << s << endl;
    return 0;
}
二分法求方程近似解
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int p, q;

double f(double x) {
    return p * x + q;
}

int main() {
    cin >> p >> q;
    double l = -20, r = 20;
    while (fabs(l - r) > 0.000001) {
        double m = (l + r) / 2;
        if (f(l) * f(m) > 0) {
            l = m;
        } else {
            r = m;
        }
    }
    printf("%.4f\n", l);
    return 0;
}
幂级数
#include <iostream>
using namespace std;

long long f(int n) {
    long long a = 1;
    for (int i = 0; i < n; i++) {
        a *= 2;
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    cout << f(n) << endl;
    return 0;
}
大小写翻转
#include <iostream>
#include <string>
using namespace std;

string f(string a) {
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 'a' && a[i] <= 'z') {
            a[i] -= 'a' - 'A';
        } else if (a[i] >= 'A' && a[i] <= 'Z') {
            a[i] += 'a' - 'A';
        }
    }
    return a;
}

int main() {
    string a;
    cin >> a;
    a = f(a);
    cout << a << endl;
    return 0;
}
最大的数
#include <iostream>
using namespace std;

int f(int n, int num[]) {
    int m = num[0];
    for (int i = 1; i <n; i++) {
        if (m < num[i]) {
            m = num[i];
        }
    }
    return m;
}

int main() {
    int n, num[100005] = {0};
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> num[i];
    }
    cout << f(n, num) << endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值