题目合集
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;
}