| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 419 人关注过本帖
标题:Where's Waldorf? 为什么总是RE无效内存引用啊,边界也有考虑啊,求解释!! ...
只看楼主 加入收藏
克莱尔小熊
Rank: 1
等 级:新手上路
帖 子:6
专家分:5
注 册:2011-7-21
结帖率:0
收藏
 问题点数:0 回复次数:1 
Where's Waldorf? 为什么总是RE无效内存引用啊,边界也有考虑啊,求解释!!!!
题目是这样的,我下面的代码测试用例输出的都是对的,边界也考虑到了,为什么还是RE无效内存引用啊,在DC和VC上都被和谐了,在VS上就编译失败,求解释啊,泪奔了都。

10. Where's Waldorf?
Background
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{

 int ca,m,n,i,j,k,z,l,len,find=0,p,man;

 char name[100][50];

 char map[150][150];

 char x[8][60];

      scanf("%d",&ca);
      getchar();
      getchar();
       memset(map, 0, sizeof(map));
      for(l=0;l<ca;l++)     // 大循环控制循环次数
      {
         scanf("%d %d",&m,&n);    //m行数,n列数   
         getchar();
         memset(map, 0, sizeof(map));
        
         for(i=0;i<m;i++)          //输入地图
          for(j=0;j<=n;j++)
            {
              scanf("%c",&map[i][j]);
              if(map[i][j]>='A'&& map[i][j]<='Z')
                map[i][j]+=32;
            }
       
         i=0;j=0;
      
         scanf("%d",&man);
         getchar();
        
         for(k=0;k<man;k++)
         {
            gets(name[k]);
         }
        
         for(k=0;k<man;k++)
         {
            
            memset(x, 0, sizeof(x));
            len=0;
            find=0;
               len=strlen(name[k]);
               for(i=0;i<len;i++)
               {
                 if(name[k][i]>='A' && name[k][i]<='Z')
                 name[k][i]+=32;
               }
               for(i=0;i<m && !find;i++)
                for(j=0;j<=n && !find;j++)
                 {
                   if(name[k][0]==map[i][j])
                   {
                     {
                      for(z=0;z<len;z++)
                       { if(i-z!=-1 && j-z!=-1)       //斜左上
                            x[0][z]=map[i-z][j-z];
                         else  x[0][z]='\0';}
                    
                      for(z=0;z<len;z++) 
                       { if(i-z!=-1)    //
                           x[1][z]=map[i-z][j];
                        else  x[1][z]='\0';}
                       
                      for(z=0;z<len;z++) 
                      { if(i-z!=-1&& j+z!=n)     //斜右上
                           x[2][z]=map[i-z][j+z];
                        else x[2][z]='\0';}
                       
                      for(z=0;z<len;z++)
                      { if(j-z!=-1)    //
                           x[3][z]=map[i][j-z]; 
                        else x[3][z]='\0';}
                      
                      for(z=0;z<len;z++) 
                      { if(j+z!=n)    //
                           x[4][z]=map[i][j+z];
                        else x[4][z]='\0';}
                     
                      for(z=0;z<len;z++) 
                      { if(j-z!=-1 && i+z!=m)   //斜左下
                           x[5][z]=map[i+z][j-z];
                        else x[5][z]='\0';}
                     
                      for(z=0;z<len;z++) 
                      { if(i+z!=m && j!=n)     //
                           x[6][z]=map[i+z][j];
                        else x[6][z]='\0';}
                     
                      for(z=0;z<len;z++) 
                      { if(i+z!=m && j+z!=n)     //斜右下
                           x[7][z]=map[i+z][j+z];
                        else x[7][z]='\0';}
                      }
                    
                    
                      for(p=0;p<8;p++)
                        {
                          if(strcmp(name[k],x[p])==0) 
                          {find=1;
                       
                           printf("%d %d\n",i+1,j+1);
                           break;
                          }
                        }                
                   }
                 }
           
          } 
        if(l<ca-1) printf("\n");     
      }   
        
      
system("pause");
}
            
                   
                       
                     
                      
                  

Given an m by n grid of letters and a list of words, find the location in the grid at which the word can be found.

A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid regardless of case (i.e., upper- and lowercase letters are to be treated as the same). The matching can be done in any of the eight horizontal, vertical, or diagonal directions through the grid.

Input
The input begins with a single positive integer on a line by itself indicating the number of cases, followed by a blank line. There is also a blank line between each two consecutive cases.

Each case begins with a pair of integers m followed by n on a single line, where 1 ≤ m, n ≤ 50 in decimal notation. The next m lines contain n letters each, representing the grid of letters where the words must be found. The letters in the grid may be in upper- or lowercase. Following the grid of letters, another integer k appears on a line by itself (1 ≤ k ≤ 20). The next k lines of input contain the list of words to search for, one word per line. These words may contain upper- and lowercase letters only – no spaces, hyphens, or other non-alphabetic characters.

Output
For each word in each test case, output a pair of integers representing its location in the corresponding grid. The integers must be separated by a single space. The first integer is the line in the grid where the first letter of the given word can be found (1 represents the topmost line in the grid, and m represents the bottommost line). The second integer is the column in the grid where the first letter of the given word can be found (1 represents the leftmost column in the grid, and n represents the rightmost column in the grid). If a word can be found more than once in the grid, then output the location of the uppermost occurrence of the word (i.e., the occurrence which places the first letter of the word closest to the top of the grid). If two or more words are uppermost, output the leftmost of these occurrences. All words can be found at least once in the grid.

The output of two consecutive cases must be separated by a blank line.

Source
http://online-judge.uva.es/p/v100/10010.html
  测试输入 期待的输出 时间限制 内存限制 额外进程
测试用例 1 以文本方式显示 1↵

8 11↵
abcDEFGhigg↵
hEbkWalDork↵
FtyAwaldORm↵
FtsimrLqsrc↵
byoArBeDeyv↵
Klcbqwikomk↵
strEBGadhrb↵
yUiqlxcnBjf↵
4↵
Waldorf↵
Bambi↵
Betty↵
Dagbert↵
 以文本方式显示 2 5↵
2 3↵
1 2↵
7 8↵
 1秒  64M  0  

搜索更多相关主题的帖子: 内存 测试 
2011-08-31 08:39
克莱尔小熊
Rank: 1
等 级:新手上路
帖 子:6
专家分:5
注 册:2011-7-21
收藏
得分:0 
求回复啊,大神帮帮忙啊
2011-08-31 11:33
快速回复:Where's Waldorf? 为什么总是RE无效内存引用啊,边界也有考虑啊,求解 ...
数据加载中...
 
   



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

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