没有合适的资源?快使用搜索试试~ 我知道了~
epic 面试题+答案
4星 · 超过85%的资源 需积分: 50 121 下载量 102 浏览量
2013-11-03
23:11:12
上传
评论 4
收藏 125KB PDF 举报
温馨提示
试读
17页
epic 公司自己总结的 面试题+答案,吐血推荐
资源详情
资源评论
资源推荐
Write algorithm to return change in denominations of 10$, 5$, 1$, 25 cents, 10 cents
double deno[]= {10, 5, 1, 0.25, 0.10, 0.05, 0.01};
//Scanner reader = new Scanner(System.in);
float cost = 67.9500f;
float cash = 100.00f;
float change = cash-cost;
System.out.println(change);
for(int i=0;i<deno.length;i++)
{
float quo = (float) ((float) change/deno[i]);
float rem = (float) ((float) change%deno[i]);
if (quo>=1)
{
float num = (float) ((float) (change-rem)/deno[i]);
System.out.printf("Number of "+deno[i]+"s: "+num+"");
change = (float) (change-(num*deno[i]));
}
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
/* Function declarations */
void giveTheChange(int dollar, int cents, vector<int> &inDollar, vector<int> &inCent);
void process(int &sum,vector<int> &denom,bool dollar);
/* Function definitions */
void giveTheChange(int dollar, int cents, vector<int> &inDollar, vector<int> &inCent){
/* Find minmum number of dollars needed to give the change */
int sum=dollar;
Business Unit/Tier 3 (Optional)
|
Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional)
|
Legal Disclaimer (Optional)
int centsLeft;
int sumCent=cents;
process(sum,inDollar,true);
if(sum!=0){
centsLeft=sum*100;
sumCent+=centsLeft;
}
process(sumCent,inCent,false);
}
void process(int &sum,vector<int> &denom,bool dollar){
while(sum!=0 && denom.size()!=0)
{
if(denom.back()<= sum )
{
sum-=denom.back();
if(dollar)
cout<<"$"<<denom.back()<<" ";
else
cout<<"##"<<denom.back()<<" ";
//inDollar.pop_back();
}
else
{
denom.pop_back();
}
}
}
int main()
{
char key;
int dollarArray[]={4};
int centArray[]={25,10};
int dollar,cents;
vector <int> inDollar(dollarArray,dollarArray+sizeof(dollarArray)/sizeof(int));
sort(inDollar.begin(), inDollar.end());
vector<int> inCent(centArray, centArray+sizeof(centArray)/sizeof(int));
Business Unit/Tier 3 (Optional)
|
Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional)
|
Legal Disclaimer (Optional)
sort(inCent.begin(), inCent.end());
cout<<"Enter the amount that you wanna make change "<<endl;
cin>>dollar ; cout<<" "; cin >>cents;
cout<<endl;
giveTheChange(dollar, cents, inDollar, inCent);
cin>>key;
return 0;
}
__________________________________*********************************______________________
Find the no, of days from 1
st
Jan to the date entered
// considering only 28 days in feb
initial_date = 01;
initial_month = 01;
initial_year = 2011; // lets say
target_date //
target_month //
target_year //
days = 0;
days += (target_year - initial_year )*365;
day = {0,31,28,31,30,31,30,31,31,30,31,30,31};
while(target_month > initial_month)
{
days += day[initial_month];
initial_month++;
}
days += target_date -01;
cout<<days;
___________________________******************************________________________________
_
Given a number find whether the digits in the number can be used to form an equation with + and '='
public class TryPlusEqual {
public static int count = 0;
Business Unit/Tier 3 (Optional)
|
Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional)
|
Legal Disclaimer (Optional)
public static int check(int n1,int n2,int n3)
{
count++;
if(n1+n2==n3)
{
System.out.println(n1+"+"+n2+"="+n3);
return 1;
}
else if(n2 + n3 == n1)
{
System.out.println(n2+"+"+n3+"="+n1);
return 2;
}
else if(n1+n3==n2)
{
System.out.println(n1+"+"+n3+"="+n2);
return 3;
}
else
return 0;
}
public static void main(String args[])
{
String f = "17512";
int n = f.length()/2;
System.out.println(n);
for(int i=0;i<n;i++)
for(int j=i+1;j<n+i+1;j++)
{
int num1 = Integer.parseInt(f.substring(0, i+1));
int num2 = Integer.parseInt(f.substring(i+1, j+1));
int num3 = Integer.parseInt(f.substring(j+1,f.length()));
int temp = check(num1,num2,num3);
if(temp == 0)
continue;
else
break;
}
System.out.println(count);
}
}
Business Unit/Tier 3 (Optional)
|
Practice Group/Tier 4 (Optional)
Proprietary & Confidential (Optional)
|
Legal Disclaimer (Optional)
剩余16页未读,继续阅读
zhenxueli
- 粉丝: 3
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论7