• 【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 }
  • 相关阅读:
    C#简单操作XML文件的增、删、改、查
    一个感觉还算可以的验证码生成程序
    安装aclocal1报错问题
    php中soap 的使用实例无需手写WSDL文件,提供自动生成WSDL文件类
    ofstream和ifstream详细用法[转]
    [原]C++ Soap客户端实例
    PHP中文件读、写、删的操作
    C++ Boost Thread 编程指南
    (转)虚函数和纯虚函数区别
    strcpy和memcpy的区别
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3642657.html
Copyright © 2020-2023  润新知