pku 3768 Repeater 字符串模拟

题意很简单,根据图形上指示的情况重复图案,然后输出结果
但是为什么G++会超时?据说用getchar读入能快很多。。
 1 # include <cstdio>
 2 # include <cstring>
 3 # include <cstdlib>
 4 using namespace std;
 5 char t[2][3500][3500];
 6 void emptyline(char *str,int len)
 7 {
 8     str[0]='\0';
 9     for(int i=0;i<len;i++)
10          strcat(str," ");
11 }
12 int main()
13 {
14     int n;
15     char str[3500];
16     while(true)
17     {
18         gets(str);
19         n=atoi(str);
20         if(!n) break;
21         for(int i=0;i<n;i++)
22             gets(t[0][i]);
23         char ori[10][10];
24         for(int i=0;i<n;i++)
25               strcpy(ori[i],t[0][i]);
26         gets(str);
27         int repeat=atoi(str);
28         bool turn=0;
29         while(--repeat)
30         {
31             int len=strlen(t[turn][0]);
32             emptyline(str,len);
33             for(int i=0;i<n*len;i++)
34                 t[!turn][i][0]='\0';
35             for(int i=0;i<n;i++)
36                 for(int j=0;j<n;j++)
37                     if(ori[i][j]!=' ')
38                         for(int k=0;k<len;k++)
39                             strcat(t[!turn][len*i+k],t[turn][k]);
40                     else
41                         for(int k=0;k<len;k++)
42                             strcat(t[!turn][len*i+k],str);
43                 
44 
45             
46             turn=!turn;
47         //    for(int i=0;i<strlen(t[turn][0]);i++)
48             //printf("%s\n",t[turn][i]);
49             //system("pause");
50         }
51         for(int i=0;i<strlen(t[turn][0]);i++)
52             printf("%s\n",t[turn][i]);
53     }
54     return 0;
55 }


posted on 2010-10-15 18:39 yzhw 阅读(182) 评论(2)  编辑 收藏 引用 所属分类: simple problem~

评论

# re: pku 3768 Repeater 字符串模拟[未登录] 2010-11-07 22:39 一棵小草

能给讲讲t开三维数组代表什么意思么?谢谢。  回复  更多评论   

# re: pku 3768 Repeater 字符串模拟 2010-11-08 12:17 yzhw

@一棵小草t[(i-1)%2][][]代表前一次操作后数组的状况
t[i%2][][]为当前的  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年1月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

公告

统计系统

留言簿(1)

随笔分类(227)

文章分类(2)

OJ

最新随笔

搜索

积分与排名

最新评论

阅读排行榜