百度笔试题交流

#include<stdio.h> 
#include<string.h>
int main(){ 
    char a[100],b[100],c[2500][100];
    scanf("%s",a);
    scanf("%s",b);
    int blen,alen,clen,i,j,sum,k;
    blen = strlen(b);
    alen = strlen(a);
    for(i = 0;i <= alen-blen;i++){
        int flag = 1;
        for(j = 0;j < blen;j++){
            if(b[j]=='?'){
                c[k][j] = a[i+j];
            }else{
                if(b[j]!=a[i+j]){
                    flag=0;
                    break;
                }else{
                    c[k][j] = a[i+j];
                }
            }
        }
        c[k][j] = '\0';
        if(flag){
            k++;
        } 
    }
    int d[10000]={0};
    for(i = 0;i<k;i++){
        if(d[i]){
            continue;    
        }
        for(j = i+1;j<k;j++){
            if(d[j]){
                continue;
            }else{
                if(!strcmp(c[i],c[j])){
                    d[j]=1;
                }
            }
        }
    }
    for(i = 0,j = 0;i < k;i++){
        if(!d[i]){
            j++;
        }
    }
    printf("%d",j);
}  
求大佬帮忙看看这个题为啥0% 提示是段错误 但是 两个字符串长度都是50以内啊#笔试题目#
全部评论
怎么记的代码??你们都是本地IDE答的??只有我傻不楞的纯手撕吗。。。
点赞 回复 分享
发布于 2018-04-18 21:32
爬山 import java.awt.List; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main1 {               public static ArrayList<Integer> list=new ArrayList<>();          public static void main(String[] args) {         System.out.println("Hello World");                  Scanner scanner=new Scanner(System.in);                  int n=scanner.nextInt();         int m=scanner.nextInt();                  int x=scanner.nextInt();         int y=scanner.nextInt();                           int a[][]=new int[n][m];                  for (int i = 0; i <n; i++) {             for(int j=0;j<m;j++) {                 a[i][j]=scanner.nextInt();             }                      }                  scanner.close();                  list.add(a[x-1][y-1]);         countWays(a,n,m,x-1,y-1);                            Collections.sort(list);                  System.out.println(list.get(list.size()-1));     }     private static void countWays(int[][] a, int n, int m, int x, int y) {                  int l1,l2,l3,l4;         l1=x+1;         l2=x-1;         l3=y+1;         l4=y-1;                                    if(l3>0&&l3<m) {             if(a[x][l3]>a[x][y]) {                              list.add(a[x][l3]);                 countWays(a, n, m, x, l3);             }         }                  if(l4>0&&l4<m) {             if(a[x][l4]>a[x][y]) {                 list.add(a[x][l4]);                 countWays(a, n, m, x, l4);             }                      }                  if(l1>0&&l1<n) {             if(a[l1][y]>a[x][y]) {                      list.add(a[l1][y]);                 countWays(a, n, m, l1, y);             }                      }                  if(l2>0&&l2<n) {                          if(a[l2][y]>a[x][y]) {                 list.add(a[l2][y]);                 countWays(a, n, m, l2, y);             }         }                                }                          }
点赞 回复 分享
发布于 2018-04-18 21:05
爬山题 import Queue as queue n, m = raw_input().strip().split() n = int(n) m = int(m) x, y = raw_input().strip().split() x = int(x) - 1 y = int(y) - 1 mm = [] visit = [] for _ in range(n): tem = raw_input().strip().split() tem = list(map(int, tem)) mm.append(tem) q = queue.Queue() saber1 = (x, y, mm[x][y]) q.put(saber1) visit.append((x, y)) mh = mm[x][y] while(not q.empty()): cx, cy, ch = q.get() if ch>=mh: mh=ch if cx-1>=0 and mm[cx-1][cy]>=ch: q.put((cx-1, cy, mm[cx-1][cy])) if cx+1<n and mm[cx+1][cy]>=ch: q.put((cx+1, cy, mm[cx+1][cy])) if cy-1>=0 and mm[cx][cy-1]>=ch: q.put((cx, cy-1, mm[cx][cy-1])) if cy+1<n and mm[cx][cy+1]>=ch: q.put((cx, cy+1, mm[cx][cy+1])) print(mh) 第二题直接print 120通过了10%(捂脸)
点赞 回复 分享
发布于 2018-04-18 21:13
是内道 输入 00010001  ?? 输出3 的那道题
点赞 回复 分享
发布于 2018-04-18 21:19
import sys def main():     n_m = sys.stdin.readline().strip('\n')     n_m = [int(i) for i in n_m.split()]     matrix = []     position = sys.stdin.readline().strip('\n')     position = [int(i) for i in position.split()]     for i in range(n_m[0]):         line_i = sys.stdin.readline().strip('\n')         line_i_num = [float(k) for k in line_i.split()]         matrix.append(line_i_num)     print(n_m, position, matrix)          result = solution(position, matrix, n_m)     sys.stdout。write(result)      def solution(position, matrix, n_m):     path = hasPath(position, matrix, n_m)     if not path:         return matrix[position[0]][position[1]]     result = []     for i in path:         if i == 1:             result.append(solution([position[0]+1, position[1]], matrix, n_m))         if i == 2:             result.append(solution([position[0]-1, position[1]], matrix, n_m))         if i == 3:             result.append(solution([position[0], position[1]+1], matrix, n_m))         if i == 4:             result.append(solution([position[0], position[1]-1], matrix, n_m))     return max(result)              def hasPath(position, matrix, n_m):     path = []     print(position)     if 0 <= position[0]+1 < n_m[0] and matrix[position[0]][position[1]] < matrix[position[0]+1][position[1]]:         path.append(1)     if 0 <= position[0]-1 < n_m[0] and matrix[position[0]][position[1]] < matrix[position[0]-1][position[1]]:         path.append(2)     if 0 <= position[1]+1 < n_m[1] and matrix[position[0]][position[1]] < matrix[position[0]][position[1]+1]:         path.append(3)     if 0 <= position[1]-1 < n_m[1] and matrix[position[0]][position[1]] < matrix[position[0]][position[1]-1]:         path.append(4)     return path            if __name__ =="__main__":     main1() 只可惜 没时间了, 不知道做的对不对
点赞 回复 分享
发布于 2018-04-18 21:23
你们是百度发的那个链接答的么?我怎么感觉看不了对错呢?只能看测试用例过没过。。
点赞 回复 分享
发布于 2018-04-18 21:24
话说最后没点最外面的 我要交卷  会凉吗。。 最后十秒钟点都没反应了。。
点赞 回复 分享
发布于 2018-04-18 21:27
百度不是不能用IDE嘛?我同学切出去用IDE直接取消考试资格的。然后0%怎么出来的啊?如果过了,难道不是显示你过了11个test case嘛?我做了一个假的百度笔试?
点赞 回复 分享
发布于 2018-04-18 21:52

相关推荐

秋招之BrianGriffin:你再跟他说华为工资也低(相对互联网)就可以享受私信爆炸了😋
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务