| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4578 人关注过本帖
标题:别管我,我就是要上头条,怎么破?
只看楼主 加入收藏
sbwl
Rank: 2
等 级:论坛游民
威 望:2
帖 子:10
专家分:18
注 册:2016-8-22
收藏
得分:0 
没看题目...直接拷贝下来改的,不过你这while判断的添加确实停不下来
2016-08-22 18:01
书生牛犊
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:星夜征程
等 级:贵宾
威 望:10
帖 子:1101
专家分:5265
注 册:2015-10-27
收藏
得分:0 
回复 11楼 sbwl
不是停不下来。是你们还不知道怎么停。


windows下输入(回车 Ctrl+Z 回车),Linux我忘了(可以百度一下)...这时候程序才能得到我说的的那个表示“输入结束”的信号。


做练习题很少会用到这个sanf()!=EOF  的判断。

φ(゜▽゜*)♪
2016-08-22 18:13
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:1 
Linux是Ctrl+D
楼主的代码压根就实现不了题目的要求。基本上要重新写过。
友情提示,数组a,b最好改成二维数组,可以降低代码难度。
2016-08-22 18:22
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1745
专家分:3216
注 册:2015-12-2
收藏
得分:1 
回复 楼主 小心飞刀hbw
下午没事写了个,有点冗长
#include<stdio.h>
 int main() {
     int  A,B,i,i1=0,j,j1=0,n,e=0;
     int t,u;
     int a[100],b[100],m=0,c[100];
     scanf("%d",&n);
     
     while(e<n)
     {
            if(scanf("%d",&A)==1) {
               
         for(i=0; i<A; i++)
         {
         scanf("%d",&a[i1]);
         i1++;
         }
            
     }
       if(scanf("%d",&B)==1) {
         for(j=0; j<B; j++)
         {
            
             scanf("%d",&b[j1]);
             j1++;
         }
            
     }
     e++;
     }
     for(i=0; i<i1; i++) {
         for(j=0; j<j1; j++)
         
             if(a[i]==b[j]) {
                 if(m==0)
                 {
                  c[m]=a[i];
                 m++;
                 }
                 
                  for(u=0; u<m;u++)
                     if(a[i]==c[u])break;
                     
                     if(u==m)
                     {
                         c[m]=a[i];
                        m++;
                     }
                     
                    
               
             }
     }
     if(m==0)printf("A,B集合没有交集");
     else if(m==1)printf("%d",c[0]);
     else
     {
         for(i=0; i<m-1; i++)
         for(j=0; j<m-1-i; j++)
             if (c[j]>c[j+1] ) {
                 t=c[j];
                 c[j]=c[j+1];
                 c[j+1]=t;
             }
     for(i=0; i<m; i++)
         printf("%d ",c[i]);
     }
     
     return 0;
 }
2016-08-22 18:37
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:1 
sanf()!=EOF 是ACM中很常见的输入判断,但不适用本题。

好久不ACM了。凑个热闹,试试这个。
程序代码:
#include<stdio.h>
#include<stdlib.h>

int cmp(const void * a, const void * b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int a[100], an, b[100], bn, n, i, j;

    for(scanf("%d", &n); n--; puts(""))
    {
        for(scanf("%d", &an), i = 0; i < an; scanf("%d", &a[i++]));
        for(scanf("%d", &bn), i = 0; i < bn; scanf("%d", &b[i++]));
        qsort(a, an, sizeof(int), cmp);
        qsort(b, bn, sizeof(int), cmp);
        for(i = j = 0; i < an && j < bn && a[i] != b[j]; a[i] < b[j] ? i++ : j++);
        if(i < an && j < bn) printf("%d", a[i]);
        for(i++, j++; i < an && j < bn; a[i] < b[j] ? i++ : a[i] > b[j] ? j++ : (printf(" %d", a[i]), i++, j++));
    }
    return 0;
}


重剑无锋,大巧不工
2016-08-22 19:55
七夜天泪
Rank: 2
等 级:论坛游民
帖 子:23
专家分:16
注 册:2016-8-16
收藏
得分:1 
回复 7楼 sbwl
谢谢  我主要是需要前面的代码  我的写完了  不知道错误出在哪了 谢了啊
2016-08-22 20:15
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1745
专家分:3216
注 册:2015-12-2
收藏
得分:0 
版主果然高手!
2016-08-22 20:18
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:0 
来凑个热闹
#include<stdio.h>                                      
#include<malloc.h>                                    
                                                      
int main() {                                          
    int i,j,n,e,m=0;                                   
    int k=0,t;                                         
    int a1,b1;                                         
    int **a,**b,**c;                                   
    scanf("%d",&n);                                    
                                                      
    //开辟空间                                            
    a=(int**)malloc(sizeof(int*)*n);                     
    b=(int**)malloc(sizeof(int*)*n);                     
    c=(int**)malloc(sizeof(int*)*n);                     
    for(i=0;i<n;i++)                                      
    {                                                     
        a[i]=(int*)malloc(sizeof(int)*100);                  
         b[i]=(int*)malloc(sizeof(int)*100);                 
        c[i]=(int*)malloc(sizeof(int)*100);                  
    }                                                     
                                                         
    //给c[i][0]赋值,计算有多少交集                       
    for(i=0;i<n;i++)                                   
        c[i][0]=0;                                       
                                                         
       //输入集合                                         
    while(m!=n)                                       
    {                                                  
        if(scanf("%d",&a[m][0])!=EOF) {                  
            for(i=1; i<=a[m][0]; i++)                           
                scanf("%d",&a[m][i]);                     
        }                                                
        if(scanf("%d",&b[m][0])!=EOF) {                  
            for(j=1; j<=b[m][0]; j++)                     
                scanf("%d",&b[m][j]);                     
        }                                                
        m++;                                             
    }                                                  
                                                      
    //将交集赋值给数组c                                
    for(i=0; i<n; i++)                                 
    {                                                     
        k=1;                                                
         for(j=1; j<=a[i][0]; j++)                           
            for(m=1;m<=b[i][0];m++)                       
                if(a[i][j]==b[i][m])                     
                {                                                  
                    c[i][k]=a[i][j];                     
                    c[i][0]++;                           
                    k++;                                 
                }                                         
   }                                                   
                                                      
   //排序                                             
    for(i=0;i<n;i++)                                   
        for(j=1;j<=c[i][0];j++)                              
            for(m=1;m<=c[i][0];m++)                             
            if(c[i][j]<c[i][m])                                 
            {                                                   
                t=c[i][j];                                         
                c[i][j]=c[i][m];                                   
                c[i][m]=t;                                         
            }                                                   
                                                               
                                                            
       //输出                                             
    for(i=0; i<n; i++)                                 
    {                                                     
        for(j=1;j<=c[i][0];j++)                              
            printf("%d\t",c[i][j]);                             
        printf("\n");                                       
    }                                                     
                                                         
    //释放空间                                            
    free(a);                                             
    free(b);                                             
    free(c);                                             
    return 0;                                          
}               

[此贴子已经被作者于2016-8-22 20:43编辑过]

2016-08-22 20:19
小心飞刀hbw
Rank: 2
等 级:论坛游民
帖 子:47
专家分:24
注 册:2016-3-21
收藏
得分:0 
回复 7楼 sbwl
谢谢了,解决了
2016-08-23 15:57
小心飞刀hbw
Rank: 2
等 级:论坛游民
帖 子:47
专家分:24
注 册:2016-3-21
收藏
得分:0 
回复 18楼 linlulu001
非常谢谢大神。
2016-08-23 15:58
快速回复:别管我,我就是要上头条,怎么破?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020494 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved