地址
http://acm.hdu.edu.cn/showproblem.php?pid=2081
定位
输入输出
水题
分析
按照字符串读入手机号码,取后5位输出
scanf("%s",arr),读入字符串,自动在字符串末尾加\0,故字符数组规模应为 11+1,避免越界。
代码
- #include <iostream>
- #include <math.h>
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- int main() {
- int N;
- char num[12];
- scanf(”%d”,&N);
- while(N–) {
- scanf(”%s”,num);
- printf(”6”);
- for(int i=6; i<11; i++) {
- printf(”%c”,num[i]);
- }
- printf(”\n”);
- }
- return 0;
- }
性能
| Exe.Time | Exe.Memory | Code Length | Language |
|---|---|---|---|
| 0MS | 1872K | 367B | c++ |
本文介绍了一个简单的程序设计问题解决方案:从输入的手机号码中提取并输出最后五位数字。使用 C++ 语言实现,通过 scanf 函数读取字符串形式的手机号码,并避免了数组越界的错误。
584

被折叠的 条评论
为什么被折叠?



