ACM第一次比赛题目及标准程序(基础水题)

来源:互联网 发布:java相关的搜索引擎 编辑:程序博客网 时间:2024/04/29 22:49

欢迎访问XYNUOJ

问题A

时间限制: 1 Sec  内存限制: 128 MB

题目描述

在魔法世界,人们的身份证号是一个12位长的数字串。如果足够优秀,人们还可以申请加入魔法工会。如果加入成功,将拥有一个工号。假设所有的工号都是是 6+身份证号的后5位,比如身份证号码为410888845678的魔法师,对应的短号就是645678。

  现在,如果给你一个12位长的身份证号码,你能找出对应的工号吗?

输入

  输入数据的第一行是一个N(N <= 200),表示有N个数据,接下来的N行每一行为一个12位的身份证号码。

输出

  输出应包括N行,每行包括一个对应的工号,输出应与输入的顺序一致。

样例输入

2
410888345678
410999454321

样例输出

645678

654321

[cpp] view plain copy
  1. #include<stdio.h>  
  2. int main()  
  3. {  
  4.     int N;  
  5.     scanf("%d",&N);  
  6.     while(N--)  
  7.     {  
  8.         long long int a;  
  9.         scanf("%lld",&a);   
  10.         printf("%lld\n",a%100000+6*100000);   
  11.     }  
  12.     return 0;  
  13. }  

[cpp] view plain copy
  1. #include<stdio.h>  
  2. int main()  
  3. {  
  4.     int i,n;  
  5.     char a[12];  
  6.     scanf("%d",&n);  
  7.     while(n--)  
  8.     {  
  9.         scanf("%s",&a);  
  10.         printf("6");  
  11.         for(i=7;i<12;i++)   
  12.         {  
  13.             printf("%c",a[i]);  
  14.         }  
  15.         printf("\n");  
  16.     }  
  17.     return 0;  
  18. }  

问题B

时间限制: 1 Sec  内存限制: 4 MB

题目描述

calculate sum(n) = 1 + 2 + 3 + ... + n。

输入

The input will consist of a series of integers n, one integer per line.

输出

For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

样例输入

1
10

样例输出

1
55

[cpp] view plain copy
  1. //计算sum(N) = 1 + 2 + 3 + ... + N  
  2. //输入多组数据 每组计算后有空行   
  3. #include<stdio.h>  
  4. int main()  
  5. {  
  6.     int a;  
  7.     while(scanf("%d",&a)!=EOF)  
  8.     {  
  9.         int sum = 0;  
  10.         for(int i = 1; i <= a; i++)  
  11.         {  
  12.             sum =  sum + i;;  
  13.         }  
  14.         printf("%d\n\n",sum);     
  15.     }  
  16.     return 0;  
  17. }   

问题 C

时间限制: 1 Sec  内存限制: 128 MB


题目描述

    胡八一今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算.
    对于大于等于100的整数, 胡八一仅保留该数的最后两位进行计算, 如果计算结果大于等于100, 那么胡八一也仅保留计算结果的最后两位.
    例如, 对于胡八一来说:
    1) 1234和34是相等的
    2) 35+80=15
    给定非负整数A和B, 你的任务是代表胡八一计算出A+B的值.

输入

输入数据的第一行为一个正整数T, 表示测试数据的组数. 然后是T组测试数据. 每组测试数据包含两个非负整数A和B(A和B均在int型可表示的范围内).

输出

对于每组测试数据, 输出胡八一A+B的结果

样例输入

3
35 80
25 80
15 1152

样例输出

15
5
67

[cpp] view plain copy
  1. #include<stdio.h>  
  2. int main()  
  3. {  
  4.     int N;  
  5.     scanf("%d",&N);  
  6.     while(N--)  
  7.     {  
  8.         int a, b, sum;  
  9.         scanf("%d%d",&a,&b);  
  10.         sum = a + b;  
  11.         sum = sum % 100;  
  12.         printf("%d\n",sum);  
  13.     }  
  14.     return 0;  
  15. }  

问题 D

时间限制: 1 Sec  内存限制: 128 MB


题目描述

    In class, kangkang learned to use the computer to solve N factorial, and then came home to show off to Jane. In order not to       let kangkang be too complacent, Jane gave kangkang a question "since you're going to ask for N factorial, you'll help me             figure out 1! + 2! -3! + 4! -5! +... N!" It is. Can you help him?

输入

The first line enters an integer T (0 < = 20), which represents T group test data.

After that, it has T rows, and each row enters a positive integer N (0 < N < = 20).

输出

Each group of test data accounts for one line, output 1! + 2! - 3! +... .. N! The value of the.

样例输入

2
2
4

样例输出

3
2
1

[cpp] view plain copy
  1. #include<stdio.h>  
  2. int main()  
  3. {  
  4.     int n;  
  5.     scanf("%d", &n);  
  6.     while (n--)  
  7.     {  
  8.         int m, i;  
  9.         long long  sum = 1;  
  10.         scanf("%d", &m);  
  11.           
  12.         for (i = 2; i <= m; i++)  
  13.         {  
  14.             long long  term = 1;  
  15.             for (int j = 2; j < i + 1; j++)  
  16.                 term *= j;  
  17.         if (i % 2 == 0)  
  18.             sum += term;  
  19.         else  
  20.             sum -= term;  
  21.         }  
  22.         printf("%lld\n",sum);  
  23.     }  
  24.     return 0;  
  25. }  

问题 E

时间限制: 1 Sec  内存限制: 128 MB
题目描述

   辉子最近接到了一个棘手的任务,他们公司有一个电话簿.但是这是一个奇怪的电话簿,因为它不是用数字记录电话号码,而是用数    字键上所对应的字母来记录电话号码(2-abc,3-def,4-ghi,5-jkl,6-mno,7-pqrs,8-tuv,9-wxyz),电话号码只有11位。现在你的任      务就是帮辉子写一个程序来把这些字母的电话号码转化成数字的电话号码。

输入

   第一行输入一个正整数T(0<T<=100),表示测试数据的组数,每组测试数据只有一行,输入一串字符(字符长度为11);

输出

   每组输出占一行,输出数字的电话号码。

样例输入

3
phqghumeayl
nlfdxfircvs
cxggbwkfnqd

样例输出

74744863295
65339347287
29442953673

[cpp] view plain copy
  1. #include<stdio.h>  
  2. #include<string.h>  
  3. int main()  
  4. {  
  5.     char a[11];  
  6.     int N, i;  
  7.     scanf("%d",&N);  
  8.     while(N--)  
  9.     {  
  10.         scanf("%s",a);  
  11.         for( i = 0; i < 11; i++){  
  12.           
  13.         if(a[i]=='a' || a[i]=='b' || a[i]=='c')  
  14.         {  
  15.             a[i] = '2';  
  16.         }  
  17.         if(a[i]=='d' || a[i]=='e' || a[i]=='f')  
  18.         {  
  19.             a[i] = '3';  
  20.         }  
  21.         if(a[i]=='g' || a[i]=='h' || a[i]=='i')  
  22.         {  
  23.             a[i] = '4';  
  24.         }  
  25.         if(a[i]=='j' || a[i]=='k' || a[i]=='l')  
  26.         {  
  27.             a[i] = '5';  
  28.         }  
  29.         if(a[i]=='m' || a[i]=='n' || a[i]=='o')  
  30.         {  
  31.             a[i] = '6';  
  32.         }  
  33.         if(a[i]=='p' || a[i]=='q' || a[i]=='r' || a[i]=='s')  
  34.         {  
  35.             a[i] = '7';  
  36.         }  
  37.         if(a[i]=='t' || a[i]=='u' || a[i]=='v')  
  38.         {  
  39.             a[i] = '8';  
  40.         }  
  41.         if(a[i]=='w' || a[i]=='x' || a[i]=='y' || a[i]=='z')  
  42.         {  
  43.             a[i] = '9';  
  44.         }  
  45.           
  46.     }  
  47.     for(i = 0; i <= 10; i++)  
  48.     {  
  49.         printf("%c",a[i]);  
  50.     }  
  51.     printf("\n");  
  52.     }  
  53.     return 0;  
  54. }  



问题 F

时间限制: 1 Sec  内存限制: 128 MB

题目描述

    一般人们把对几乎所有抗生素有抗药性的细菌统称为超级细菌。有一个超级细菌,它每秒增殖出一个小细菌。每个小细菌经过生     长,从第四秒开始,每秒也生一个小细菌。请编程实现在第n秒的时候,共有多少个细菌?假设超级细菌不会死亡或者消失。输入

    输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<30),n的含义如题目中描述。
    n=0表示输入数据的结束,不做处理。

输出

    对于每个测试实例,输出在第n秒的时候细菌的数量。
    每个输出占一行。

样例输入

2
4
5
0

样例输出

2
4
6
[cpp] view plain copy
  1. #include<stdio.h>  
  2. int cow(int n)  
  3. {  
  4.     if(n < 4)  
  5.     {  
  6.         return n;  
  7.     }else{  
  8.         return cow(n-1)+cow(n-3);  
  9.     }  
  10. }  
  11. int main()  
  12. {  
  13.     int n;    
  14.     while(scanf("%d",&n)!=EOF && n!=0)  
  15.     {  
  16.         printf("%d\n",cow(n));  
  17.     }   
  18. }   



问题G

时间限制: 1 Sec  内存限制: 128 MB

题目描述

   在ACM算法研究所中,科学家为了更快更好的处理实验数据,决定将一整串的数字按照一定的规则分隔开来,分隔规则如下:

   1、实数的整数部分按照每三个数字用逗号分隔开(整数部分的高位有多余的0时,需先将多余的0过滤后,再进行数字分隔,如:         0001234567 输出结果为1,234,567.00)

   2、小数部分保留两位小数(四舍五入)

   3、如果该数是负的,则在输出时需用括号将分隔后的数字括起来,例如:-10005.1645的输出结果为(10,005.16)  

输入

   多组测试数据(以eof结尾),每行输入一个实数n(n的位数小于100)

输出

输出分隔后的结果

样例输入

0001234567
0.0000
-10005.1645

样例输出

1,234,567.00
0.00
(10,005.16)


问题 H

时间限制: 1 Sec  内存限制: 128 MB

题目描述

    Calculate the volume of the ball according to the radius of the input.

输入

    The input data has a number of groups, each of which consists of a row, which includes a real number representing         the radius of the sphere.

输出

    The output corresponds to the volume of the ball. For each group of input data, the output row, the calculation               results retain the three decimal places.

样例输入

1
1.5
2.55

样例输出

4.189
14.137
69.456

提示


#define PI 3.1415927

V=4/3*PI*r*r*r.


[cpp] view plain copy
  1. //计算球体积   
  2. #include<stdio.h>  
  3. #define PI 3.1415927  
  4. int main()  
  5. {  
  6.     double r;  
  7.     while(scanf("%lf",&r)!=EOF)  
  8.     {  
  9.         printf("%.3lf\n",4.0/3.0*PI*r*r*r);  
  10.     }  
  11.     return 0;  
  12. }