zoukankan      html  css  js  c++  java
  • 字符转换

    //4.编写一个程序,可以一直接收键盘字符,
    //如果是小写字符就输出对应的大写字符,
    //如果接收的是大写字符,就输出对应的小写字符,
    //如果是数字不输出。
    void String(){
        char ch = 0;
        while (1){
            printf("请输入:>");
            fflush(stdin);
            scanf("%c", &ch);
            if (96 < ch&&ch < 123)
                printf("%c
    ", (ch - 32));
            else if (64 < ch&&ch < 91)
                printf("%c
    ", (ch + 32));
            else
                continue;
            
        }
    }
    
    //3.编写代码模拟三次密码输入的场景。
    //最多能输入三次密码,密码正确,提示“登录成功”, 密码错误,
    //可以重新输入,最多输入三次。三次均错,则提示退出程序。
    void scanf_password(){
        char ch[1024] = { 0 };
        int count = 0;
        while (1){
            printf("请输入密码:>");
            scanf("%s", ch);
            if (strcmp(ch, "123456") == 0){
                printf("被你蒙对了
    ");
                break;
            }
            count++;
            if (count == 5){
                printf("请30s后再次输入
    ");
                count = 0;
                Sleep(30000);
            }
        }
    }
    //2.写代码可以在整型有序数组中查找想要的数字,
    //找到了返回下标,找不到返回 - 1.(折半查找)
    int binary_search(int arr[], int len,int target){
        int start = 0;
        int end = len - 1;
        while (start <= end){
            int mid = (end - start) / 2 + start;
            if (arr[mid] < target){
                start = ++mid;
            }
            else if (arr[mid]>target){
                end = --mid;
            }
            else
                return mid;
        }
        return -1;
    }
  • 相关阅读:
    每天一个css text-indent
    每天一个css word-break word-wrap white-space
    [转载]CentOS+nginx+uwsgi+Python+django 环境搭建
    【转】django使用model创建数据库表使用的字段
    Django对mysql操作
    mysql增删改查
    mysql用户管理
    centos7启动mysql
    centos安装python3
    [转载]python学习目录(转至袁先生的博客)
  • 原文地址:https://www.cnblogs.com/du001011/p/10054545.html
Copyright © 2011-2022 走看看