浙大acm1755经验总结

本文探讨了在编程中正确理解字符串长度与数组定义之间的关系,特别关注了一个实例,说明了忽略字符串在数组中存放规则导致的问题。文章强调了在处理字符串时,不仅要考虑字符数量,还需注意到字符串末尾的空字符标记'',并提供了改进后的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There are one or more classes of students, followed by a final line containing only the value -1. Each class starts with a line containing an integer, n, which is the number of students in the class, followed by n lines of student information. Each line of student information consists of three positive integers, representing the dimensions of the clay block, followed by the student's first name. There can never be more than 9 students nor less than 2 students in any class. Each student's name is at most 8 characters. Ms. Terry always gives each student at most 250 cubic units of clay. There is exactly one bully and one victim in each class.

代码都是简单的,关键没通过的原因是:对字符串的理解不够,什么是最多八个字符?直接定义字符数组name[8]?,其实我在这里忽略了字符串在数组中的存放原则,它最终要在后面加上一个'\0',才能构成字符串,所以应该定义为name[9],以后一定要注意,加油!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值