字节跳动-traing

  1. 找零:Z国的货币系统包含面值1元、4元、16元、64元共计4种硬币,以及面值1024元的纸币。现在小Y使用1024元的纸币购买了一件价值为N (0 < N \le 1024)N(0<N≤1024)的商品,请问最少他会收到多少硬币?
    其具体实现的C++代码-01:
#include<iostream>
#include<array>

using namespace std;

int main()
{
   int n;
   while(cin>>n)
    {
       int rmb[4] = {64,16,4,1}; 
       int rst = 1024-n;
       int ans = 0;           
           for(int i=0;i<4;i++)
           {
               if(rst>0)
               {
                 ans += rst / rmb[i];
                 rst = rst % rmb[i];   
               }                         
           }     
        cout<<ans<<endl;       
   }
    return 0;
}

其具体实现的C++代码-02:

#include<iostream>
#include<array>

using namespace std;

int main()
{
   int n;
   while(cin>>n)
    {
       int a=0,b=0,c=0,d=0,ans=0,kk; 
       int rst = 1024-n;
       a = (rst-rst%64)/64;
       kk = rst%64;
       b = (kk-kk%16 )/16;
       kk = kk%16;
       c = (kk-kk%4)/4;
       d = kk%4;
       ans = a+b+c+d;
       cout<<ans<<endl;           
   }
    return 0;
}
  1. 数列的和:数列的定义如下:数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。
    其具体实现代码如下:
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main()
{
   int m;
    double n;
     double ans = 0;
    while(cin>>n>>m)
    {
       double ans = 0;
        for(int i=0;i<m;i++)
        {
            ans+=n;
            n=sqrt(n);
        }
        cout<<fixed<<setprecision(2);
        cout<<ans<<endl;
    }
    return 0;
}
  1. 查出一个成绩表中成绩最高的学生的名字(考虑并列)

表:student 字段:name,score
其具体实现的SQL语句如下:

select name from student where score = (select max(score) from student);
  1. 给定一个无序数组arr,数组中的元素可为正,为负或为0,先给出一个数k,求出数组arr连续元素和为k的最长字符串,返回该字符串长度;
  2. 水仙花数:春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+3^3。 现在要求输出所有在m和n范围内的水仙花数。输入两个整数m和n(100<=m<=n<=999),要求输出所有在给定范围内的水仙花数;
    其具体实现的代码如下:
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
   int m,n;
   while(cin>>m>>n)
   {
    if((m>=100&&m<=999) && (n>=100&&n<=999))
     {
      int g=0,s = 0,b = 0,sum=0;           
       bool flag = false;
         for(int i=m;i<=n;i++)
        {
           b = i/100;
           g = (i-b*100)/10;
           s = i-b*100-g*10;           
           sum = pow(g,3)+pow(s,3)+pow(b,3);  
           if(i == sum) 
           {
               flag = true;
               cout<<i<<" ";
           }          
        }
          if(flag == false)  cout<<"no";    
          cout<<endl;      
    }
   }   
    return 0;
}
  1. XXXX
  2. x
  3. x
  4. xx
  5. xxx\x
  6. x
    10.xXXX
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值