voip
风的方向
厚德致远,博学敦行!
posts - 52,comments - 21,trackbacks - 0
           str_cat()函数自定义:
#include<stdio.h>
char * str_cat(char *s1,char *s2)
{
    
char *s;
    s
=(char *)malloc(strlen(s1)+strlen(s2)+1);
    strcpy(s,s1);
    strcpy(s
+strlen(s1),s2);
    
return s;
}

int main()
{
    
char s1[10],s2[10];
    
char *s3;
    
while(scanf("%s %s",s1,s2)!=EOF)
    
{
        s3
=str_cat(s1,s2);
        puts(s3);
    }

    
return 0;
}
 
   报数题:
#include<stdio.h>
#include
<stdlib.h>
#include
<string.h>
int main()
{
    
int s[100];
    
int n,m,i,j,temp,k,g;
    
while(scanf("%d%d%d",&n,&m,&g)!=EOF)//n为总人数,m为开始报数人序号,g为报数循环数 
    {
        
int j=m;
        memset(s,
0,sizeof(s));
        
for(i=1;i<n;i++)
        
{
            temp
=0;
            
while(temp<g)
            
{
                
if(s[j]==0)
                    temp
++;
                
if(temp==g)
                    
break;
                j
++
                
if(j>n)
                
{
                    
for(k=1;k<=n;k++)
                        
if(s[k]==0)
                        
{
                            j
=k;
                            
break;
                        }

                }

            }

            s[j]
=1;
        
//    printf("%d\n",j);
            for(k=1;k<=n;k++)
            
{
                    printf(
"%d ",s[k]);
            }

            printf(
"\n");
        }

        
for(k=1;k<=n;k++)
        
{
            
if(s[k]==0)
            
{
                    printf(
"最后留下同学序号:%d\n",k); 
                    
break;
            }

        }


    }

    
return 0;
}

一个五位数*4=这个数的逆序题:
#include<math.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
void Numtostring(int num,char s[])  //自定义数字转换成字符串函数 
{
    
int temp,i=0;
//    char *s;
//    s=(char *)malloc(500); 
    
//char s[500];
    while(num!=0)
    
{
        temp
=num%10;
        s[i]
=temp+48;
        i
++;
        num
=num/10;    
    }

    s[i]
='\0';
    strrev(s);
}

int main()
{
    
int i;
    
int num;
    
char s[500],s0[500];
    
for(i=10000;i<100000;i++)
    
{
        num
=i*4;
        
//printf("%d\n",num);
        Numtostring(i,s);
        Numtostring(num,s0);
    
//    printf("%s\n",s);
        strrev(s0);
        
if(strcmp(s,s0)==0)
        printf(
"%d*4=%s\n",i,strrev(s));
                    
    }

    
return 0;
}
 

posted on 2010-10-29 20:28 jince 阅读(144) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


哈哈哈哈哈哈