摘要: 1.scanf函数 最常用的输入函数算是scanf函数了,要注意的就是它遇到空格、tab和回车就会停止读取,并且空格、tab和回车符仍存在于缓冲区中,如果下一个读取的是字符的话就得注意了。2.fgets函数 作用:读取完整的一行数据 用法:char buf[MAXN]; fgets(buf, MAXN, fin); 说明:这个函数一旦读到回车符'\n'就会停止读取,并把'\n'读到字符串中。此外,该函数只读取不超过MAXN-1个字符,然后再末尾添上结束符'\0',因此不会出现越界的情况。 实例:View Code 1 #include <s 阅读全文
posted @ 2013-04-18 18:58 xiaobaibuhei 阅读(314) 评论(0) 推荐(0)
摘要: 大数加法,代码如下:View Code 1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxn = 1000; 8 9 struct bign 10 { 11 int d[maxn]; 12 int len; 13 14 bign() 15 { 16 memset(d, 0, sizeof(d)); 17 ... 阅读全文
posted @ 2013-04-18 18:21 xiaobaibuhei 阅读(222) 评论(0) 推荐(0)
摘要: 大数加法,代码如下:View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxn = 1000; 8 9 struct bign 10 { 11 int d[maxn]; 12 int len; 13 14 bign() 15 { 16 memset(d, 0, sizeof(d)); 17 ... 阅读全文
posted @ 2013-04-18 18:10 xiaobaibuhei 阅读(532) 评论(0) 推荐(0)
摘要: 《算法竞赛入门经典》5.2.2,关于大数的题,按照书上给的方法超时了,计算次数太多了,没有充分利用int,最后又在网上搜了一下,修改代码如下:View Code 1 #include <cstdio> 2 #include <cstring> 3 4 const int maxn = 1000; 5 int f[maxn]; 6 7 int main() 8 { 9 #ifdef LOCAL10 freopen("in", "r", stdin);11 #endif12 int n;13 while(scanf("%d& 阅读全文
posted @ 2013-04-18 16:21 xiaobaibuhei 阅读(224) 评论(0) 推荐(0)
摘要: 《算法竞赛入门经典》5.1.3的题,给定一个字符串,输出它的最小周期,要注意的是最后一个数据后不要跟空行,不然会WA,代码如下:View Code 1 #include <cstdio> 2 #include <cstring> 3 4 int main() 5 { 6 #ifdef LOCAL 7 freopen("in", "r", stdin); 8 #endif 9 int n;10 scanf("%d", &n);11 char s[100];12 while(n--)13 {14 scanf 阅读全文
posted @ 2013-04-18 14:37 xiaobaibuhei 阅读(1128) 评论(0) 推荐(0)
摘要: 《算法竞赛入门经典》5.1.1的题, 代码如下。View Code 1 #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 5 char table[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; 6 7 int main() 8 { 9 #ifdef LOCAL10 freopen("in", "r", stdin);11 #endif12 int c;13 wh 阅读全文
posted @ 2013-04-18 13:40 xiaobaibuhei 阅读(135) 评论(0) 推荐(0)
摘要: 目前只找到一部分uva上的题目,其它的应该是没有了,或者我还没找到...注:带有“类似”标记的题目表明为类似的题目,可能与例题有些出入,但不是很大,用的是同样的方法。第五章:5.1.1 WERTYUUVa10082 - WERTYU5.1.2 TEX括号UVa272 - TEX Quotes5.1.3 周期串UVa455 - Periodic Strings5.2.1 小学生算术UVa10035 - Primary Arithmetic5.2.2 阶乘的精确值UVa623 - 500!5.3.1 6174问题5.3.2 字母重排UVa642 - Word Amalgamation5... 阅读全文
posted @ 2013-04-18 13:20 xiaobaibuhei 阅读(348) 评论(0) 推荐(0)