zoukankan      html  css  js  c++  java
  • 2017.10.27

      

    时间限制:1秒 空间限制:32768K 热度指数:22626

     算法知识视频讲解

    题目描述

    给定一个十进制的正整数number,选择从里面去掉一部分数字,希望保留下来的数字组成的正整数最大。

    输入描述:

    输入为两行内容,第一行是正整数number,1 ≤ length(number) ≤ 1000。第二行是希望去掉的数字数量cnt 1 ≤ cnt < length(number)。

    输出描述:

    输出保留下来的结果。
    示例1

    输入

    325
    1
    

    输出

    35



      

    #include <iostream>
    #include <stdio.h>
    #include <math.h>
    #include <iomanip> //不能写成#include <iomanip.h>
    using namespace std;
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */

    int main(int argc, char** argv)
    {
    int number,k;
    int array[3]; //将 百、十、个位 从小到大排序
    int array1[3]; //保留百、十、个位
    cin>>number;
    cin>>k;

    array[0]=number/100; //分离百、十、个位
    array[1]=number/10%10;
    array[2]=number%10;

    array1[0]=number/100; //分离百、十、个位
    array1[1]=number/10%10;
    array1[2]=number%10;

    for(int i=0;i<3;i++) //将 百、十、个位 从小到大排序
    {
    int j=i-1;
    int temp=array[i];
    while(j>=0&&array[j]>temp)
    {
    array[j+1]=array[j];
    j--;
    }
    array[j+1]=temp;
    }
    // cout<<array[0]<<setw(3)<<array[1]<<setw(3)<<array[2]<<endl; //调试用,输出 百、十、个位
    switch(k) //根据K的数值分类
    {
    case 0:break;
    case 1:
    {
    if(array1[0]==array[0])
    {
    cout<<number%100<<endl;
    }
    if(array1[1]==array[0])
    {
    cout<<array1[0]*10+array1[2]<<endl;
    }
    if(array1[2]==array[0])
    {
    cout<<number/10<<endl;
    }
    // cout<<array[0]<<setw(3)<<array[1]<<setw(3)<<array[2]<<endl;
    }
    break;
    case 2:
    {
    if(number<100)
    cout<<"Error"<<endl;
    if(number>99&&number<1001)
    cout<<array[2]<<endl;
    }
    break;
    case 3:
    {
    if(number<1000)
    cout<<"Error"<<endl;
    if(number==1000)
    cout<<1<<endl;
    }
    break;
    default:break;
    }
    return 0;
    }

    
    
  • 相关阅读:
    C#_委托
    一个asp+ACCESS省市二级联动菜单程序
    asp怎么实现二级联动下拉菜单
    ASP用户登录代码
    Windows 2003 IIS 不支持ASP的问题
    iptables
    VNC ( Virtual Network Computing )
    MongoDB的备份(mongodump)与恢复(mongorestore)
    Locally managed (LMT) vs. Dictionary managed (DMT) tablespace
    向现有的磁盘组加入/删除ASM磁盘
  • 原文地址:https://www.cnblogs.com/panlangen/p/7746003.html
Copyright © 2011-2022 走看看