• Coursera课程笔记----C程序设计进阶----Week 8&9


    面向对象入门&期末考试(Week 8&9)

    面向对象

    • 什么是计算机程序
      • 现实世界的解决方案在计算机系统中的映射
    • 编程语言
      • 帮助我们实现映射的工具
    • 面向对象语言
      • 比其他语言更加先进

    期末考试

    Quiz1 含k个3的数

    #include <iostream>
    using namespace std;
    int main()
    {
        int m,k;
        cin >> m >> k;
    
        int temp = m;
        int count = 0;
        while (temp != 0)
        {
            int a = temp % 10;
            if(a == 3)
                count++;
            temp = temp / 10;
        }
        if(m % 19 == 0 && count == k)
            cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    
        return 0;
    
    }
    

    Quiz2 字符串中次数第二多的字母

    //我觉得这道题我写的实在是太乱太乱了Orz
    //反正OJ是过啦!但是感觉写的太弱智了Orz
    #include <iostream>
    using namespace std;
    int main()
    {
        int count[26] = {0};
        char low[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        char high[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
        char sequence[26] = {''};
        char a[500] = {''};
        int counter = 0;
        cin.getline(a,500);
    
        for (int i = 0; a[i] != ''; i++) {
            for (int j = 0; j < 26; j++) {
                if(a[i] == low[j] || a[i] == high[j])
                {
                    if(count[j] == 0)
                    {
                        sequence[counter] = low[j];
                        counter++;
                    }
                    count[j]++;
                    break;
                }
            }
        }
    
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26-i-1; j++) {
                if(count[j] < count[j+1])
                {
                    int temp = count[j];
                    count[j] = count[j+1];
                    count[j+1] = temp;
                    char temp1 = low[j];
                    low[j] = low[j+1];
                    low[j+1] = temp1;
                }
            }
        }
    
        int max = count[0];
        int submax = 0;
        for (int i = 0; i < 26; i++) {
            if(count[i] < max)
            {
                submax = count[i];
                break;
            }
        }
    
        int flag = 0;
        char sublow[26] = {''};
        for (int i = 0; i < 26; i++) {
            if(count[i] == submax)
            {
                sublow[flag] = low[i];
                flag++;
            }
        }
    
        if(flag == 1)
        {
            cout<<char(sublow[0] - 32) <<'+'<<sublow[0]<<':'<<submax<<endl;
        } else if (flag > 1)
        {
            char only = '';
            int call = 0;
            for (int i = 0; sequence[i] != ''; i++) {
                for (int j = 0; j < flag; j++) {
                    if(sequence[i] == sublow[j] && call == 0)
                    {
                        only = sublow[j];
                        call = 1;
                    }
                }
            }
            cout<<char(only - 32) <<'+'<<only<<':'<<submax<<endl;
        }
    
        return 0;
    }
    

    Quiz3 运算符判定

    #include <iostream>
    using namespace std;
    int main()
    {
        int a,b,c;
        char d,e;
        cin >> a >> d >> b >> e >> c;
    
        if(c == a + b)
            cout<<'+'<<endl;
        else if(c == a - b)
            cout<<'-'<<endl;
        else if(c == a * b)
            cout<<'*'<<endl;
        else if(c == a / b)
            cout<<'/'<<endl;
        else if(c == a % b)
            cout<<'%'<<endl;
        else cout<<"error"<<endl;
    
    }
    

    Quiz4 寻找平面上的极大点

    #include <iostream>
    using namespace std;
    int main()
    {
        int a[100]={0},b[100]={0};
        int a1[100]={0},b1[100]={0};
        int index = 0;
        int n;
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i] >> b[i];
        }
    
        for (int i = 0; i < n; i++) {
            int flag = 0;
            for (int j = 0; j < n; j++) {
                if(a[i] <= a[j] && b[i] <= b[j] && i != j )
                    flag = 1;
            }
            if(flag == 0)
            {
                a1[index] = a[i];
                b1[index] = b[i];
                index++;
            }
        }
    
        for (int i = 0; i < index; i++) {
            for (int j = 0; j < index-i-1; j++) {
                if(a1[j] > a1[j+1])
                {
                    int temp = a1[j];
                    a1[j] = a1[j+1];
                    a1[j+1] = temp;
                    temp = b1[j];
                    b1[j] = b1[j+1];
                    b1[j+1] = temp;
                }
            }
        }
    
        for (int i = 0; i < index; i++) {
            cout<<'('<<a1[i]<<','<<b1[i]<<')';
            if(i != index-1)
                cout<<',';
        }
        return 0;
    }
    

    Quiz5 走出迷宫

    //暂时没有思路,回头补
    
  • 相关阅读:
    二、Python基础练习
    代码测试服同步到生产服务器
    支付宝网站支付 异步验签成功 同步验签失败
    最近机房让整改的漏洞 设置cookie httponly X-Frame-Options头未设置
    连连支付,或微信或支付宝支付,商品名称最后一个字乱码,php解决
    ci 框架新手使用
    php制作公司五章,圆形印章和椭圆形印章,正方形印章,圆角正方形印章,圆角框
    Libreoffice php使用命令行office转pdf,pdf转图片
    后台返回数据回显,使用js控制默认选中复选框和下拉框
    Nginx日志按日期切割详解(按天切割)
  • 原文地址:https://www.cnblogs.com/maimai-d/p/12868691.html
Copyright © 2020-2023  润新知