算法竞赛入门经典第4章 【uvaoj习题(一)】

题目合集

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94


uva10055

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=996

“ These two numbers in each line denotes the number of soldiers in Hashmat's army and his opponent's army or vice versa.”

注意到vice versa这个题目就可以过了,英文阅读能力啊

#include <stdio.h>

int
main(void)
{
	long long a, b;

	while (scanf("%lld %lld", &a, &b) != EOF) {
		printf("%lld\n", a>b ? a-b : b-a);
	}
	return 0;
}


uva10071

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=1012

#include <stdio.h>

int
main(void)
{
	int v, t;

	while (scanf("%d %d", &v, &t) != EOF)
		printf("%d\n", v*t*2);
	return 0;
}


uva100300

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=1241

按题意有一个(a/b)*b*c的过程,因此要写成a*c

#include <stdio.h>

int
main(void)
{
	int tc, x, a, b, c;
	int permium;

	scanf("%d", &tc);
	while (tc--) {
		scanf("%d", &x);
		permium = 0;
		while (x--) {
			scanf("%d %d %d", &a, &b, &c);
			permium += a*c;
		}
		printf("%d\n", permium);
	}
	return 0;
}


uva458

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=399

其实就是除了换行符,其他字符都作一个相对平移后输出

#include <stdio.h>

int
main(void)
{
	int c;

	while ((c = getchar()) != EOF)
		putchar(c == '\n' ? '\n' : c-('1'-'*'));
	return 0;
}



uva494

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=435

用ctype.h写出来的程序可读性比较好哦

注意fgets的用法,遇到回车符就停止读取,并且把回车符读入,这个gdb可以查看,遇到EOF会返回NULL

虽然str的值等于str[0],但是sizeof 这个两个东西结果是不同的。可以想象str是一个包含整个数组的长方框,而str[0]是一个元素的单位方框,sizeof关键词返回的是单位方框数

#include <stdio.h>
#include <ctype.h>
#define N 10000
char str[N];

int
main(void)
{
	char *p = NULL;
	int count;
	
	while (fgets(str, sizeof (str), stdin) != NULL) {
		count = 0;
		for (p = str; *p != '\n'; p++) {
			if (isalpha(*p) && !isalpha(*(p+1)))
				count++;
		}
		printf("%d\n", count);
	}
	return 0;
}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值