IT民工
加油!
摘要: 这道题是要我们找出所有蚂蚁中最靠近端点和最靠近中间的蚂蚁所在的位置,计算端点的蚂蚁爬到另一个端点的时间和计算靠近中间的蚂蚁爬到离他近的端点的时间。我们只需分输入的位置在棒的左边还是右边来讨论就行。#include<iostream>using namespace std;int main(){ int cas; int l, n, a; cin >> cas; while( cas --) { cin >> l >> n; int ans, earliest = 0, latest = 0; while( n --) ... 阅读全文
posted @ 2011-11-04 14:41 找回失去的 阅读(238) 评论(0) 推荐(0)
摘要: #include<stdio.h>#include<string.h>char ch[105][105];int main(){ int cnt = 0, ans = 0; while( gets(ch[cnt])) { int len = strlen( ch[cnt]); if( len > ans) ans = len; cnt ++; } for(int j = 0; j < ans; j ++) { for( int i = cnt - 1; i >= 0; i --) { ... 阅读全文
posted @ 2011-11-04 13:01 找回失去的 阅读(551) 评论(0) 推荐(0)
摘要: 本来这应该是一道很简单的题的,但是题目对空格的要求很高,所以我WA了好几次。而且读入数据的时候我居然加了getchar();...这也是WA的罪魁祸首!贴代码:#include<iostream>#include<stdio.h>using namespace std;int main(){ int n, a, f; cin >> n; int cas = 0; while( n --) { if( cas ++) printf("\n"); cin >> a >> f; while( f -- ) { ... 阅读全文
posted @ 2011-11-03 22:53 找回失去的 阅读(504) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2503这是一道字符串处理的题。有点写字典,查字典的意思,首先要解决的是输入字典和查字典时输入单词中间的那一个空行,我是用gets输入前面的东西,所以只需一个判断就可以跳出输入字典的循环。然后是输入单词翻译,因为字典当中的单词比较多,我又不会hash,所以用了二分查找。#include<stdio.h>#include<string.h>#include<stdlib.h>#define M 100003typedef struct dictionary{ char f[15]; char n[15];}D 阅读全文
posted @ 2011-11-03 12:42 找回失去的 阅读(283) 评论(0) 推荐(1)
摘要: 继续做白书的题,发现基础还得补。这道题是变化版的3n+1问题,给定初始的A,然后再给一个limit数,当运算过程中的中间数超过了limit或者A = 1结束运算,要我们求这个过程的运算次数ans。#include<cstdio>int main(){ long long a, b; int cnt = 0; while( true) { cnt ++; scanf( "%lld%lld", &a, &b); if( a == -1 && b == - 1) break; long long n = a; ... 阅读全文
posted @ 2011-11-03 10:16 找回失去的 阅读(298) 评论(0) 推荐(0)
摘要: 每个字符剪去7就能翻译过来了#include<stdio.h>#include<string.h>char ch[1000];int main(){ while( gets(ch) != NULL ) { int len = strlen(ch); for(int i = 0; i < len; i ++) { printf("%c", ch[i] - 7); } printf("\n"); } return 0;} 阅读全文
posted @ 2011-11-03 00:23 找回失去的 阅读(221) 评论(0) 推荐(0)
摘要: 这道题的标题中的幼儿园让人看得郁闷,计算单词的数目...#include<stdio.h>#include<stdlib.h>#include<ctype.h>#include<string.h>char ch[1000];int main(){ char a[100]; while( gets(ch) != NULL) { int len = strlen(ch); int cnt = 0; for(int i = 0; i <= len; i ++) { if( isalpha( ch[i] )... 阅读全文
posted @ 2011-11-03 00:21 找回失去的 阅读(276) 评论(0) 推荐(0)
摘要: 这道题做的很郁闷,用gets始终A不了,然后用了fegets就A了,难道是题意理解不对?#include<stdio.h>#include<string.h>#include<stdlib.h>char ch[150];int main(){ int k = 0; while( fgets( ch, 150, stdin) ) { int len = strlen(ch); for(int i = 0; i < len; i ++) { if( ch[i] > '0' && ch[i] <= '9&# 阅读全文
posted @ 2011-11-03 00:14 找回失去的 阅读(309) 评论(0) 推荐(0)
摘要: 这题看得有点迷糊,但是用了下灵格斯就懂题意了,直接上代码:#include<iostream>using namespace std;int main(){ int n, f, a, b, c; while(cin >> n) { while( n --) { cin >> f; int sum = 0; for( int i = 0; i < f; i ++) { cin >> a >> b >> c; ... 阅读全文
posted @ 2011-11-03 00:10 找回失去的 阅读(175) 评论(0) 推荐(0)
摘要: 这道题要我们先将10进制数x和y在B进制下进行加法取模运算,然后再将结果转换成10进制。#include<iostream>#include<string.h>using namespace std;const int MAX = 32;int a[MAX], b[MAX];int main(){ int n, cas, B, x, y; cin >> n; while(n --) { cin >> cas >> B >> x >> y; int j = 0; while(x > 0) { a... 阅读全文
posted @ 2011-10-31 14:35 找回失去的 阅读(277) 评论(0) 推荐(1)