zoukankan      html  css  js  c++  java
  • 【HDOJ】1073 Online Judge

    这道题TLE了N多次,完全不明白为什么,稍微改了一下,居然过了。使用gets过的,看讨论帖有人还推荐用hash。

      1 #include <stdio.h>
      2 #include <string.h>
      3 
      4 #define LOCAL 0
      5 #define MAXNUM 5005
      6 #define isSpace(ch) (ch==' '||ch=='	'||ch=='
    ')
      7 
      8 char stand[MAXNUM];
      9 char data[MAXNUM];
     10 char word[MAXNUM];
     11 
     12 int main() {
     13     int n, len1, len2, i, j, flg;
     14 #if LOCAL
     15     FILE *fout = fopen("data", "w");
     16 #endif
     17     scanf("%d%*c", &n);
     18 
     19     while (n--) {
     20         scanf("%*s%*c");   // START
     21         len1 = 0;
     22         while (1) {
     23             if (gets(word) == NULL) {
     24                 stand[len1++] = '
    ';
     25                 continue;
     26             }
     27             if ( !strcmp(word, "END") )
     28                 break;
     29             strcpy(stand+len1, word);
     30             len1 += strlen(word);
     31             stand[len1++] = '
    ';
     32         }
     33         stand[len1++] = '';
     34         scanf("%*s%*c");   // START
     35         len2 = 0;
     36         while (1) {
     37             if (gets(word) == NULL) {
     38                 data[len2++] = '
    ';
     39                 continue;
     40             }
     41             if ( !strcmp(word, "END") )
     42                 break;
     43             strcpy(data+len2, word);
     44             len2 += strlen(word);
     45             data[len2++] = '
    ';
     46         }
     47         data[len2++] = '';
     48 #if LOCAL
     49         fprintf(fout, "standard:
    %s", stand);
     50         fprintf(fout, "data:
    %s", data);
     51 #endif
     52         i = j = flg = 0;
     53         while (i<len1 && j<len2) {
     54             if (stand[i] == data[j]) {
     55                 j++;
     56                 i++;
     57             } else {
     58                 if ( isSpace(stand[i]) ) {
     59                     flg = 1;
     60                     i++;
     61                 } else if ( isSpace(data[j]) ) {
     62                     flg = 1;
     63                     j++;
     64                 } else {
     65                     flg = 2;
     66                     break;
     67                 }
     68             }
     69         }
     70         if (flg == 2) {
     71             printf("Wrong Answer
    ");
     72             continue;
     73         }
     74         while (i<len1) {
     75             if ( isSpace(stand[i]) )
     76                 flg = 1;
     77             else {
     78                 flg = 2;
     79                 break;
     80             }
     81             ++i;
     82         }
     83         while (j<len2  && flg!=2) {
     84             if ( isSpace(data[j]) )
     85                 flg = 1;
     86             else {
     87                 flg = 2;
     88                 break;
     89             }
     90             ++j;
     91         }
     92         if (flg==2)
     93             printf("Wrong Answer
    ");
     94         else if (flg==1)
     95             printf("Presentation Error
    ");
     96         else
     97             printf("Accepted
    ");
     98     }
     99 #if LOCAL
    100     fclose(fout);
    101 #endif
    102     return 0;
    103 }
  • 相关阅读:
    IDEA中Git实战
    高并发下redis缓存穿透问题解决方案
    springboot整合mybatis+generator
    Github修改项目显示的语言类型
    Github中README.md换行
    maven中可以直接引用的java系统属性和环境变量属性
    springboot启动异常java.lang.NoSuchFieldError: DEFAULT_INCOMPATIBLE_IMPROVEMENTS
    java获取Linux持续运行时间及友好显示
    http工具类
    idHTTP最简洁的修改和取得Cookie例子
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3642657.html
Copyright © 2011-2022 走看看