| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2235 人关注过本帖
标题:ZOJ的2016题Segmentation Fault求解!
只看楼主 加入收藏
resign
Rank: 1
等 级:新手上路
帖 子:18
专家分:2
注 册:2015-3-13
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:23 
ZOJ的2016题Segmentation Fault求解!
#include"stdio.h"
#include"string.h"
#define maxn 1000
int main()
{
     int n,t;
     scanf("%d\n",&n);
     int i,j,k[n],l;
     for(i=0;i<n;i++)
     {
         k[i]=1;
     }
     for(i=0;i<n;i++)
      {
         scanf("%d\n",&t);
         char s[t][maxn];
         for(j=0;j<t;j++)
            fgets(s[j],sizeof(s[j]),stdin);
        for(j=0;j<t;j++)
         {
           l=strlen(s[j]);
            if(s[j][l-2]!=s[j+1][0]&&j<t-1)
              {
                k[i]=0;
              }
         }
      }
      for(i=0;i<n;i++)
         if(k[i]==1)
            printf("Ordering is possible.\n");
         else
            printf("The door cannot be opened.\n");
      return 0;
}
是哪里的数组越界了吗?
搜索更多相关主题的帖子: include 
2015-05-08 09:59
ID永哥
Rank: 1
等 级:新手上路
帖 子:2
专家分:1
注 册:2015-5-8
收藏
得分:0 
声明数组的时候,数组名+[常量表达式],你改改试试
2015-05-08 10:33
resign
Rank: 1
等 级:新手上路
帖 子:18
专家分:2
注 册:2015-3-13
收藏
得分:0 
回复 2楼 ID永哥
仍然是显示Segmentation Fault..
2015-05-08 10:46
hzj199603
Rank: 2
来 自:南京
等 级:论坛游民
帖 子:18
专家分:32
注 册:2015-3-29
收藏
得分:0 
回复 楼主 resign
定义数组的时候中括号里不能是变量
2015-05-08 13:11
resign
Rank: 1
等 级:新手上路
帖 子:18
专家分:2
注 册:2015-3-13
收藏
得分:0 
回复 4楼 hzj199603
可是输入n或者是t之后n和t的值就没变了呀,为什么不行?
2015-05-08 14:45
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:10 
不是你的数组操作越界了,而是你的数组太大了,存放它的那点空间不够。你还不了解变长数组,只看到了它方便使用的特点,还不清楚使用它的限制。

而且,这还不是重点,即使你的数组有足够的空间,也得不到正确的结果,此题并不是你想的那么简单。当然也不难,但你缺乏相关的图论基础。

并不是想打击你,且不说你的数学基础不够,就是语言基础也差的很远。暂时还解不了这样的问题。其实我也很想知道现在这里有几个人能解这个问题

重剑无锋,大巧不工
2015-05-09 00:18
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
没人响应?谁第一个解出来我赠送100专家分。可以再提示一下——欧拉路径。

下面是题目的完整描述。地址为http://acm.zju.
Play on Words


Time Limit:  5 Seconds      Memory Limit:  32768 KB

Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us.
There is a large number of magnetic plates on every door. Every plate has one word written on it. The plates must be arranged into a sequence in such a way that every word begins with the same letter as the previous word ends. For example, the word "acm" can be followed by the word "motorola". Your task is to write a computer program that will read the list of words and determine whether it is possible to arrange all of the plates in a sequence (according to the given rule) and consequently to open the door.


Input

 The input consists of T test cases. The number of them (T) is given on the first line of the input. Each test case begins with a line containing a single integer number Nthat indicates the number of plates (1 <= N <= 100000). Then exactly Nlines follow, each containing a single word. Each word contains at least two and at most 1000 lowercase characters, that means only letters 'a' through 'z' will appear in the word. The same word may appear several times in the list.


Output

 Your program has to determine whether it is possible to arrange all the plates in a sequence such that the first letter of each word is equal to the last letter of the previous word. All the plates from the list must be used, each exactly once. The words mentioned several times must be used that number of times.

 If there exists such an ordering of plates, your program should print the sentence "Ordering is possible.". Otherwise, output the sentence "The door cannot be opened.".


Sample Input

 3
 2
 acm
 ibm
 3
 acm
 malform
 mouse
 2
 ok
 ok


Sample Output

 The door cannot be opened.
 Ordering is possible.
 The door cannot be opened.

重剑无锋,大巧不工
2015-05-09 20:58
resign
Rank: 1
等 级:新手上路
帖 子:18
专家分:2
注 册:2015-3-13
收藏
得分:0 
回复 6楼 beyondyf
感谢版主大人指教,那么语言基础还需要学什么,是要了解内存的分配吗。。新人刚学C语言没多久,能推荐本书也行,感谢!
2015-05-10 11:09
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
回复 8楼 resign
你不妨先回答下面几个问题。

1、全局变量与局部变量有什么不同?为什么全局变量有默认初始值,而局部变量没有?

2、静态变量与自动变量有什么区别?静态全局变量有什么意义?静态函数又有什么意义?

3、什么是指针函数?什么是函数指针?

重剑无锋,大巧不工
2015-05-11 08:23
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:0 
看来英语不行也是个麻烦啊

一片落叶掉进了回忆的流年。
2015-05-11 09:37
快速回复:ZOJ的2016题Segmentation Fault求解!
数据加载中...
 
   



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

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