zoj 1151 Word Reversal-------------输入输出超时
来源:互联网 发布:网络暴力 编辑:程序博客网 时间:2024/06/04 19:13
程序意思不难,不过就是对于输入输出的问题。
一开始时候,使用的是cin cout,但是,注意超时!
================================引用说明分割线============================================
“超时有很多原因,有的是算法的问题,但是你的程序没算法问题。所以只能是另外的一种可能,就是输入输出的问题。
你使用的c++标准输入输出cin cout 还有标准字符串类string,这些都是c++的对象或类,在使用的时候都要建立对象,使用起来速度很慢。在对小规模的acm问题时不影响,但是对输入量非常大的时候,使用cin cout明显比scanf和printf要慢的多。
string也是比vector<char>慢,而vector<char>又比char[]慢。。。 ”
================================引用说明分割线============================================
所以,什么直接把cin cout 改成scanf printf,超时问题就解决了...
另外值得注意的,还有对stack,string等的应用。好用,但也要注意超时的问题。
下面附上自己的代码以及网上找来的代码,人家用到了诸如char[],putchar getchar等...惭愧..
==================================又是我,华丽分割线======================================
#include <iostream>
#include <stack>
#include<stdio.h>
using namespace std;
int main()
{
}
网上找来的代码:
- #include
<stdio.h> - #include
<string.h> - int
i, lines; - int
total, now; - char
s[250]; //用数组来代替!!我用stack,大工程!! - char
c; -
- int
main() - {
- #ifdef
ONLINE_JUDGE - #else
-
freopen( "r", stdin); - #endif
-
scanf( &total); -
(now = 0; now < total; now++) -
{ -
scanf( &lines); //IMPORTANTplus \n -
(lines-- >= 0) -
{ -
i = 0; -
((c = getchar()) != EOF) //getchar putchar等的应用 -
{ -
(c '== ' || '\n')c == -
{ -
(i-- > 0) -
putchar(s[i]); -
putchar(c); -
(c '\n')== -
-
i = 0; -
} -
-
{ -
s[i++] = c; -
} -
} -
} -
} - #ifdef
ONLINE_JUDGE - #else
-
fclose(stdin); - #endif
-
0; - }
- zoj 1151 Word Reversal-------------输入输出超时
- zoj 1151 Word Reversal
- ZOJ 1151 Word Reversal
- ZOJ 1151 Word Reversal
- zoj 1151 Word Reversal
- zoj 1151 Word Reversal
- ZOJ 1151 Word Reversal
- ZOJ 1151: Word Reversal
- ZOJ 1151 Word Reversal
- ZOJ 1151 Word Reversal
- zoj 1151 Word Reversal
- zoj 1151 Word Reversal
- zoj 1151 Word Reversal
- ZOJ 1151 Word Reversal
- php - zoj 1151 Word Reversal
- ZOJ Problem Set - 1151 Word Reversal
- ZOJ-1151 Word Reversal,栈的解法
- ZOJ Problem Set - 1151 Word Reversal
- 数理逻辑:公理化算术(7)递归项
- 那些所谓的中国企业(转)
- 我的第三十四个C++上机报告(数组大折腾)
- 国产InitPHP框架系列 - 两年沉淀,InitPHP3.2.2 框架发布,一个轻量级PHP框架
- 数理逻辑:公理化算术(8)有限算术
- zoj 1151 Word Reversal-------------输入输出超时
- Unity3D Shader官方教程翻译(二)
- snd_pcm_ops
- Unity3D Shader官方教程翻译(三)----Shader语法:属性
- 【JavaWeb前传系列】第04章_DIV与CSS标准化网页布局
- Linux Shell 通配符、元字符、转义符使用实例介绍
- Unity3D Shader官方教程翻译(四)----Shader语法:SubShader
- 数理逻辑:公理化算术(9)递归函数
- 幻灯片效果