华为 10第二题 成都 约瑟夫环

http://blog.csdn.net/zy6778324/article/details/11708555

每套第三题貌似有点难度,先稍微休息下。

#include <stdio.h>
#include <stdlib.h>
struct Jose
{
 int e;
 Jose *next;
}Jose;

int main()
{
 int n,m;
 int i,j;
 struct Jose *head;
 struct Jose *q;  //前一个
 struct Jose *p;  //当前
 while(scanf("%d %d",&n,&m)!=EOF&&n>0&&m>0)
 {
  head = (struct Jose*)malloc(sizeof(struct Jose));
  head->e = 1;
 // head->next = head;
  q = head;
  for(i=2;i<=n;i++)
  {
   p = (struct Jose*)malloc(sizeof(struct Jose));
   p->e = i;
  // printf("%d---------",p->e);
   q->next = p;
   q = p;
  }
  q->next = head;
  p = head;

  for(i=n;i>1;i--)
  {
   for(j=1;j<m;j++)   //
   {
    q = p;
    p = p ->next; 
   }
   q->next = p->next;
   printf("%d---
",p->e);
   free(p);
   p = q->next;
  }

  printf("%d",p->e);
 }
 return 0;
}

华为 10第二题 成都 约瑟夫环

每套第三题貌似有点难度,先稍微休息下。   #include #include struct Jose {  int e;  Jose *next; }Jose; int main() {  int n,m;  int i,j;  struct Jose *head;  struct Jose *q;  //前一个  struct Jose *p;  //当前 ...
阅读(55) 评论(0)
 

华为 成都第二套 字符串转换

#include int main() {  char c;  while(scanf("%c",&c)!=EOF)  {   if(c==' ')    continue;   printf("%c ",(c-'0'+'a'));  }  return 0; }...
阅读(58) 评论(0)
 

大数加法,华为 程度2

#include #include int main() {  char s1[130];  char s2[130];  char result[261];  int len1,len2;  int i,j,k;  while(scanf("%s %s",s1,s2)!=EOF)  {   printf("%s ",s1);   printf("%s ",s2);...
阅读(19) 评论(0)
 

华为:输入整数字符串,求最大数与最小数之和

#include #include #include int comp(const void *a,const void *b) {  return *(char *)b - *(char *)a; } int main() {  char in[200];  char pos[51];  char neg[51];  int len1;  int i,k1,k...
阅读(27) 评论(0)
 

大树乘法的代码,自己写的 贴下

大数乘法: #include #include using namespace std; #define N 999 class Mult { private:  char result[N];  char *m1;  char *m2;  int len1;  int len2; public:  Mult(char *p1,char *p2,int a1,int...
阅读(10) 评论(0
原文地址:https://www.cnblogs.com/Adrian99/p/3326623.html