首页 > 其他分享 >7.11

7.11

时间:2023-07-11 20:45:33浏览次数:36  
标签:7.11 构造方法 int num include num1

#include<iostream>
#include<math.h>
using namespace std;
int num1(int a) {
    int t = a;
    int num = 1;//纪录输入数据的位数
    for (int i = 0; i < 100; i++) {
        if (t / 10 > 0) {
            num++;
            t /= 10;
        }
        else {
            break;
        }
    }
        return num;
    }
void show(int a){
    int t = a;
    int n;
    int num = num1(a);
    while (num-- > 0) {
        n = a / (int)pow(10.0, num);
        switch (n) {
        case 0:
            cout << " ling";
            break;
        case 1:
            cout << " yi";
            break;
        case 2:
            cout << " er";
            break;
        case 3:
            cout << " san";
            break;
        case 4:
            cout << " si";
            break;
        case 5:
            cout << " wu";
            break;
        case 6:
            cout << " liu";
            break;
        case 7:
            cout << " qi";
            break;
        case 8:
            cout << " ba";
            break;
        case 9:
            cout << " jiu";
            break;
        }
        a = a % (int)pow(10.0, num);
    }
    cout << "\n";
}

int main() {
    int a;//输入的数据
    int t;//暂时储存a的值
    cin >> a;
    t = a;
    if (a < 0) {
        cout << "fu";
        a *= (-1);
        show(a);
    }
    else {
        int num = num1(a);
        int n = a / (int)pow(10.0, (num-1));
        switch (n) {
        case 0:
            cout << "ling";
            break;
        case 1:
            cout << "yi";
            break;
        case 2:
            cout << "er";
            break;
        case 3:
            cout << "san";
            break;
        case 4:
            cout << "si";
            break;
        case 5:
            cout << "wu";
            break;
        case 6:
            cout << "liu";
            break;
        case 7:
            cout << "qi";
            break;
        case 8:
            cout << "ba";
            break;
        case 9:
            cout << "jiu";
            break;
        }
        a = a % (int)pow(10.0,(num-1));

        show(a);
    }

    return 0;
}

 这个题目一直没能完全实现,难点在于他的输出格式和适用性

我打的这个代码虽然格式正确但是适用性不足,如果出现1025这种数据中间有0存在就无法输出正确结果

网课今天看了类的构造方法和C不同的是JAVA在构造方法前也要加上public

还看了私有成员,私有成员的每一个成员前都要加上private

标签:7.11,构造方法,int,num,include,num1
From: https://www.cnblogs.com/xuxingkai/p/17545866.html

相关文章

  • 2023.7.11 训练
    1.dp相关1.1path给定一个\(n∗m\)的网格,你在左下角\((n,1)\),一开始你面向上方,你只能往前走或者右拐,障碍和走过的点不能走。求走到\((x,y)\)的方案数的值,取模。\(n,m\le40\)观察到一右拐,就会进入一个子矩形,并只能在这里面移动了。设状态\(f(a,b,x,y,0..3)\)表示从......
  • 7.11
    十、打印对象classStudent{   publicStringname;   publicintage;   publicdoubleweight;    publicStudent(Stringname,intage,doubleweight){       this.name=name;       this.age=age;       this.wei......
  • (2023.7.11)usb: ring buffer full
    现象:在对usb接口的5G模组灌包时出现异常打印,xhci-hcdxhci-hcd.0.auto:ERRORunkown eventtype37/USBGadgetDriver定义了很多traceevent,使用者可以在用户空间通过ftrace接口,追踪USBGadgetDriver的行为;/用户空间接口路径为/sys/kernel/debug/tracing/events/dwc3:包含了......
  • 7.11
    上午去了邢台南和参加科目一考试在那里等了好久好久都有点不耐烦了从八点半等到了十点多才开始考感觉脑子里的东西忘得很快但是好消息是顺利地考完了93分顺利通过下午也是按照进度学习了功课......
  • 2023.7.11
    学习java类中的方法方法的声明:权限修饰符 返回值类型 方法名(形参列表){方法体}方法的说明:关于权限修饰符:Java规定的4种权限修饰符:private、public、缺省、protected如果方法有返回值,则必须在方法声明时,指定返回值的类型。同时,方法中,需要使用return关键字来返回指定类型的......
  • Cisco Catalyst 8000 Series Edge Platforms, IOS XE Release Dublin-17.11.01a ED
    CiscoCatalyst8000SeriesEdgePlatforms,IOSXEReleaseDublin-17.11.01aEDCiscoCatalyst8000边缘平台系列请访问原文链接:https://sysin.org/blog/cisco-catalyst-8000/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgCiscoCatalyst8000:随心所欲访问位于......
  • Cisco Catalyst 9800-CL Wireless Controller for Cloud, Release Dublin-17.11.01 ED
    CiscoCatalyst9800-CLWirelessControllerforCloud,ReleaseDublin-17.11.01ED面向云的思科Catalyst9800-CL无线控制器,专为基于意图的网络全新打造请访问原文链接:https://sysin.org/blog/cisco-catalyst-9800-cl/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.......
  • Cisco Catalyst 9000 Series Switches, IOS-XE Release Dublin-17.11.1 ED
    CiscoCatalyst9000SeriesSwitches,IOS-XEReleaseDublin-17.11.1EDCiscoCatalyst9000交换产品系列请访问原文链接:https://sysin.org/blog/cisco-catalyst-9000/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org接入和核心交换机与Wi-Fi6解决方案的产品组......
  • Cisco ISR 4000 Series IOS XE Release Dublin-17.11.1a ED
    CiscoISR4000SeriesIOSXEReleaseDublin-17.11.1aED思科4000系列集成服务路由器请访问原文链接:https://sysin.org/blog/cisco-isr-4000/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org思科4000系列集成服务路由器让您的分支机构站点为实施全数字化转型......
  • 7.11 字符串比较
    demo1equalsequalsIgnoreCaseStringstrA="mldn";StringstrB="MLDN";System.out.println(strA.equals(strB));System.out.println(strA.equalsIgnoreCase(strB));//不区分大小写来比较demo2compareTo字符串大小比较,com......