wujr5 / c-and-cpp-language-learning

C和C++编程语言学习 - 2015级
67 stars 34 forks source link

软件:week2 问题反馈+扩展练习 #3

Open ghostbody opened 8 years ago

ghostbody commented 8 years ago

问题反馈

本周题目仍然较为简单,大概60多个同学课上把一周的题目都做完了。

\ 学有余力的同学最好做一下扩展练习题 **

存在如下一些问题: 1、scanf("%d", &a) 的第一个参数是格式化字符串,在要求键盘输入多个变量时候,格式化字符串中间不应该用逗号隔开,格式化字符串中也不应该出现换行符号。同时,输入的时候应该要使用取地址符号&,不使用则会出错。以下几种情况均为错误的:

   scanf("%d,%d", &a, &b); 
   scanf("%d%d\n", &a, &b);
   scanf("%d%d", &a &b);
   scanf("%d%d", a, b);

正确写法:

   scanf("%d%d", &a, &b);

2、printf中前面是格式化字符串,很多同学不理解printf的机制。

   int year = 2015;
   int month = 9;
   int day = 28;

   printf("%d年%d月%d日", year, month, day);

也就是说前面的格式化字符串定义了输出的格式,其中%d是等待某个整型变量来填充进去的意思。

printf中的变量带有取地址符号是不能输出我们期望输出的变量的。 printf格式化字符串中的参数和后面不对应也是错误的。 以下写法是错误的:

   printf("%d %d", &a, &b);
   printf("%d %d", a);
   printf("hello world!\n", a);

3、记得输出需要换行

4、空格和回车在输入整数时候的作用是相同的: 1 2 3 4 与 1 2 3 4 若都是输入4个整数,这两者是一样的。

扩展练习

1000 Triangle II

Time Limit: 1sec Memory Limit:256MB

Description:

输入一个数,输出对应的这样的图像: link

1001 A/B

Time Limit: 1sec Memory Limit:256MB

Description:

输入两个整数A和B,输出这两个整数的商A除以B,保留两位小数。 注意:当除数为0时候应当输出“Error!”

input

3 5

output

0.60

input

1 0

output

Error!

HINT:

注意使用浮点数运算

1002 Polynomial II

Time Limit: 1sec Memory Limit:256MB

Description:

Given two pair of integers (a1,b1) and (a2,b2),can you calculate the expanded form of (a1x+b1)(a2x+b2)? (note that we use "x^2" to express x2 and omit "") 这次你需要考虑系数为0的情况,即: 2x^2+0x+1, 这样应该写成: 2x^2+1

input

1 0 1 0

output

x^2

1003 Sum the digits in a big integer

Time Limit: 1sec Memory Limit:256MB

Description:

Write a program that reads an integer with 3 digits and adds all the digits in the integer.For example,if an integer is 932,the sum of all its digits is 9+3+2=14. 现在要假设处理的数字非常大( 2^64 < length <= 10^200 )

(length 指的是数字的大小!不是长度!╮(╯▽╰)╭)

input

123456789011121314151617181920

output

101

扩展练习题测试数据

第二周测试数据

评测地址

YOJ 在线评测(校园内网)

ReganFan commented 8 years ago

0基础的表示不会做扩展题·····

ghostbody commented 8 years ago

那就先看好书本,等到感觉会做的时候再做,扩展题不占课程成绩,可做可不做,能做则有提升。

ReganFan commented 8 years ago

好吧