历年华为机试

#include<iostream>//一亿以内的数 用程序读出来 比如输入1234 输出 yi qian er bai san shi si  
using namespace std;
void weishu(int len);
void Change(char num )
{
	int i;
	 
	
	switch(num)
	{
	case'0':
		{
			cout<<"零";
		}
		break;
	case'1':
		{
		cout<<"壹";
		} 
		 
		 break;
		
	case'2':
		{
			cout<<"贰";
		  
		} 
		 
		 break;
	case'3':
		{cout<<"叁";
	 } 
	  
		
		 break;
	case'4':
		{cout<<"肆";
		 
		 	}  
		  break;
	
	case'5':
		{cout<<"伍";
  
		} 
		break;
	case'6':
		{cout<<"陆";
  
		} 
		break;
	case'7':
		{cout<<"柒";
  
		} 
		break;
		case'8':
		{cout<<"捌";
  
		} 
		break;
	    case'9':
		{cout<<"玖";
  
		} 
		 break;
	}


}
void weishu(int len)
{ 
	switch(len)
	{
	case 2:case 6:
		cout<<"拾";
		break;
	case 3 :case 7:
		cout<<"佰";
		break;
	case 4:case 8:
		cout<<"千";
		break;
	case 5:
		cout<<"万";
	    break;
	case 9:
		cout<<"亿";
		break;
	}
	 
}
int main()
{
	char num[10];
	int len,i,flag;
	cin>>num;
	len=strlen(num);
	i=0; 
	while(len)
	{
	Change(num[i]);
	weishu(len);
	len--;
	i++;
	}
	 
	system("pause");
	return 0;
}
typedef struct ListNode
{
	int data;
	ListNode *next;
}*List;
void JosephusGreate(List L,int n)
{
	List Lpre,Lcurr;
	
	int i=1;
	
	Lpre=NULL;
	Lcurr=NULL;
	Lpre=(ListNode*)(malloc)(sizeof(ListNode));
	Lpre=L;
   
	while(--n>0)
	{
		i++;
	    Lcurr=(ListNode*)(malloc)(sizeof(ListNode));
		Lcurr->data=i;
		Lpre->next=Lcurr;  //get wrong !!
		Lpre=Lcurr;
	}
	Lpre->next=L;
	
}
void JosephusDelete(List L,int m)
{
	List Lpre,Lcurr;
	int i=1;
	Lpre=L;Lcurr=L;
	while(Lcurr!=NULL)
	{
		if(i==m)
		{
			cout<<Lcurr->data<<endl;
			Lpre->next=Lcurr->next;
			free(Lcurr);
			Lcurr=Lpre->next;
			i=1;
		}
		Lpre=Lcurr;
		Lcurr=Lcurr->next;
		if(Lpre==Lcurr)
		{
			cout<<Lcurr->data<<endl;
			free(Lcurr);
			break;
		}
		i++;
	}
	
}
 int main()
 {
	 List head;int n,m;
	 
	 cin>>n>>m;
	 head=(ListNode*)(malloc)(sizeof(ListNode));
	 
	 head->data=1;
	 head->next=NULL;
	 JosephusGreate(head,n);
	 JosephusDelete(head,m);
	 return 0;
 }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值