手机短号
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 57 Accepted Submission(s) : 32
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
大家都知道,手机号是一个11位长的数字串,同时,作为学生,还可以申请加入校园网,如果加入成功,你将另外拥有一个短号。假设所有的短号都是是 6+手机号的后5位,比如号码为13512345678的手机,对应的短号就是645678。
现在,如果给你一个11位长的手机号码,你能找出对应的短号吗?
Input
输入数据的第一行是一个N(N <= 200),表示有N个数据,接下来的N行每一行为一个11位的手机号码。
Output
输出应包括N行,每行包括一个对应的短号,输出应与输入的顺序一致。
Sample Input
2
13512345678
13787654321
Sample Output
645678
654321
Source
2006/1/15 ACM程序设计期末考试
int类型最大值是Integer.MAX_VALUE = 21 4748 3647
所以使用long型
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// System.out.println(Integer.MAX_VALUE);//21 4748 3647
Scanner sc= new Scanner(System.in);
int n = sc.nextInt();
while(n-->0){
long number = sc.nextLong();
long five = number % 100000;
System.out.println(600000 + five);
}
sc.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for(int i = 0;i<N;i++) {
String str = sc.next();
String arr[] = str.split("");
System.out.println("6" + arr[6] + arr[7] + arr[8] + arr[9] + arr[10]);
}
sc.close();
}
}
#include<stdio.h>
int main()
{
int i, n;char g[100];
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
for(i=0;i<n;i++)
{
scanf("%s",g);
printf("6%c%c%c%c%c\n",g[6],g[7],g[8],g[9],g[10]);
}
}
return 0;
}
scanf()函数中,可用%md指定读取位数,我们可以只读取需要的,其余的不用理会。 如果在 % 后有一个 " * " 号,这是一个附加说明符,表示读取时跳过它指定的列数。 例如%*6d%4d%2d%2d 表示读入6位整数但不赋值给任何变量。然后再读入4位整数、2位整数,2位整数,最后读取结束。
#include<cstdio>
int main()
{
int a,n,i;
scanf("%d",&n);
while(n--)
{
scanf("%*6d%5d",&a);
printf("6%05d",a);
printf("\n");
}
return 0;
}
如果在 % 后有一个 " * "号,这是一个附加说明符,表示读取时跳过它指定的列数。
#include<stdio.h>
int main() {
int a,n;
scanf("%d",&n);
while(n--) {
scanf("%*6d%d",&a);
printf("6%05d\n",a);
}
return 0;
}
1945

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



