设为首页 加入收藏

TOP

华为最新笔试题——编程题及答案(五)
2014-11-23 20:20:24 来源: 作者: 【 】 浏览:64
Tags:华为 最新 试题 编程 答案
r[calstack.top--];
temp2=calstack.str[calstack.top];
calstack.str[calstack.top]=temp2+temp1;
}
else if(postexp[i]=='-')
{
temp1=calstack.str[calstack.top--];
temp2=calstack.str[calstack.top];
calstack.str[calstack.top]=temp2-temp1;
}
else if(postexp[i]=='*')
{
temp1=calstack.str[calstack.top--];
temp2=calstack.str[calstack.top];
calstack.str[calstack.top]=temp2*temp1;
}
else if(postexp[i]=='/')
{
temp1=calstack.str[calstack.top--];
temp2=calstack.str[calstack.top];
calstack.str[calstack.top]=temp2/temp1;
}
}
printf("%d\n",calstack.str[calstack.top]);
return calstack.str[calstack.top];
}
main()
{
char *expStr = "6+8*4-9/2";
int len=strlen(expStr);
calculate(len,expStr);
return 0;
}
德州扑克问题:一副牌中发五张扑克牌给你:让你判断数字的组成:
有以下几种情况:
1:四条:即四张一样数值的牌(牌均不论花色)2:三条带 一对
3:三条带两张不相同数值的牌
4:两对
5:顺子 包括 10,J,Q,K,A
6:什么都不是
7:只有一对
答案:
#include "stdio.h"
void sort(int data[],int n)
{
int temp=0;
for(int i=0;i {
for(int j=i+1;j {
if(data[i] {
temp=data[i];
data[i]=data[j];
data[j]=temp;
}
}
}
}
void test(int a[],int len)
{
int *b=new int[len];
int count=0;
bool temp=false;
for(int i=0;i {
b[i]=a[i];
}
sort(b,5);
for(i=0;i {
if(b[i]==b[i+1])
count++;
}
switch (count)
{
case 0:
if (b[0]-b[4]==4&&b[0]-b[3]==3&&b[0]-b[2]==2&&b[0]-b[1]==1)
{
printf("顺子");
}
else
printf("什么都不是");
break;
case 1:
printf("只有一对");
break;
case 2:
for(i=0;i<3;i++)
{
if(b[i]==b[i+2])
{
printf("三条带两张不相同数值的牌");
temp=true;
break;
}
}
if(!temp)
{
printf("两对");
}
break;
case 3:
if(b[1]==b[3])
printf("四条:即四张一样数值的牌");
else
printf("三条带一对");
break;
}
}
main()
{
int a[5]={3,3,3,3,12};
test(a,5);
return 0;
}
删除数组中的重复元素
#include
using namespace std;
int de(int a[],int n)
{
for (int i=0;i for (int j=i+1;j if (a[j]==a[i])
{
for (int k=j;k a[k]=a[k+1];
n--;
}
for ( i=0;i cout< cout< return 0;
}


int main ()
{int a[10];
int m=10;
for (int l=0;l<10;l++)
cin>>a[l];
de(a,m);
return 0;
}
链表逆序:
node *reverse(node *head)
{
node *p1,*p2,*p3;
if(head==NULL||head->next)
return head;
p1 = head,p2 = p1->next;
while(p2)
{
p3=p2->next;
p2->next=p1;
p1=p2;
p2=p3;
}
head->next = NULL;
head = p1;
return head;
}


首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇构建企业网络类面试题 下一篇操作系统笔试题及答案(3)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: