zoukankan      html  css  js  c++  java
  • 【南阳OJ分类之语言入门】80题题目+AC代码汇总

    小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位。

    本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载。

    声明:

           题目部分皆为南阳OJ题目。

        代码部分包含AC代码(可能不止一个)和最优代码,大部分都是本人写的,并且大部分为c代码和少部分c++代码and极少java代码,但基本都是c语言知识点,没有太多差别,可能代码有的写的比较丑,毕竟知识有限。

       语言入门部分题基本都较为简单,是学习编程入门的很好练习,也是ACM的第一步,入门的最佳方法,望认真对待。

        本文由csdn-jtahstu原创,转载请注明出处,欢迎志同道合的朋友一起交流学习。本人QQ:1373758426和csdn博客地址,链接:http://blog.csdn.net/jtahstu

       该分类南阳OJ地址:我是地址,链接:http://acm.nyist.edu.cn/JudgeOnline/problemset.php?typeid=1

    Now begin

    1、

    A+B Problem

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:0
    描述
    此题为练手用题,请大家计算一下a+b的值
    输入
    输入两个数,a,b
    输出
    输出a+b的值
    样例输入
    2 3
    样例输出
    5
    提示
    例如:
    C语言版:
    #include<stdio.h>
    int main()
    {
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d
    ",a+b);
    } 

    C++版:
    #include<iostream>
    using namespace std;
    int main()
    {
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
    }
    

    Java版:
    import java.io.*;
    import java.util.*;
    public class Main
    {
    public static void main(String args[]) throws Exception
    {
    Scanner cin=new Scanner(System.in);
    int a=cin.nextInt(),b=cin.nextInt();
    System.out.println(a+b);
    }
    }
    

    Java jdk 1.4 版
    import java.io.*;
    import java.util.*;
    
    public class Main
    {
    public static void main (String args[]) throws Exception
    {
    BufferedReader stdin =
    new BufferedReader(
    new InputStreamReader(System.in));
    
    String line = stdin.readLine();
    StringTokenizer st = new StringTokenizer(line);
    int a = Integer.parseInt(st.nextToken());
    int b = Integer.parseInt(st.nextToken());
    System.out.println(a+b);
    }
    }

    请注意不要输出过多提示性语句(如:“please input two numbers”),不然会WrongAnswer的
     
    #include<stdio.h>
    int main()
    {
       int a,b;
       scanf("%d%d",&a,&b);
       printf("%d
    ",a+b);
    } 
     
    #include<iostream>
    main(){std::cout<<(1<<31)-1;}        
            

    4、

    ASCII码排序

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述
    输入三个字符(可以重复)后,按各字符的ASCII码从小到大的顺序输出这三个字符。
    输入
    第一行输入一个数N,表示有N组测试数据。后面的N行输入多组数据,每组输入数据都是占一行,有三个字符组成,之间无空格。
    输出
    对于每组输入数据,输出一行,字符中间用一个空格分开。
    样例输入
    2
    qwe
    asd
    样例输出
    e q w
    a d s
    来源
    网络
    上传者
    naonao
    #include<stdio.h>
    #define MAX 3
    char a[MAX];
    int main() {
    	int n;
    	scanf("%d
    ", &n);
    	while (n--) {
    		char x, y, z;
    		scanf("%s", a);
    		x = a[0];
    		if (a[1] < x)
    			x = a[1];
    		if (a[2] < x)
    			x = a[2];
    		z = a[2];
    		if (a[1] > z)
    			z = a[1];
    		if (a[0] > z)
    			z = a[0];
    		y = a[0] + a[1] + a[2] - x - z;
    		printf("%c %c %c
    ", x, y, z);
    	}
    	return 0;
    }
    
    #include "stdio.h"//最优程序
    main()
    {
    	char a,b,c,d;
    	int i;
    	scanf("%d",&i);
    	getchar();
    	while(i--)
    	{
    		scanf("%c%c%c",&a,&b,&c);
    		getchar();
    		if (a>b) {d=a;a=b;b=d;}
    		if (a>c) {d=a;a=c;c=d;}
    		if (b>c) {d=b;b=c;c=d;}
    		printf("%c %c %c
    ",a,b,c);
    
    	}
    
    }
    

    11、

    奇偶数分离

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    有一个整型偶数n(2<= n <=10000),你要做的是:先把1到n中的所有奇数从小到大输出,再把所有的偶数从小到大输出。
    输入
    第一行有一个整数i(2<=i<30)表示有 i 组测试数据;
    每组有一个整型偶数n。
    输出
    第一行输出所有的奇数
    第二行输出所有的偶数
    样例输入
    2
    10
    14
    样例输出
    1 3 5 7 9 
    2 4 6 8 10 
    
    1 3 5 7 9 11 13 
    2 4 6 8 10 12 14 
    
    
    来源
    [苗栋栋]原创
    上传者
    苗栋栋
    # include"stdio.h"
    int main() {
    	int i, b, c, d, j, k;
    	scanf("%d", &i);
    	for (d = 0; d < i; d++) {
    		scanf("%d", &b);
    		for (k = 1; k <= b; k++) {
    			if ((k % 2) == 1)
    				printf("%d ", k);
    		}
    		printf("
    ");
    		for (j = 1; j <= b; j++) {
    			if ((j % 2) == 0)
    				printf("%d ", j);
    		}
    		printf("
    ");
    	}
    	return 0;
    }
    
    #include<stdio.h>//最优程序
    int main() {
    	int n;
    	scanf("%d", &n);
    	int a;
    	while (n--) {
    		scanf("%d", &a);
    		for (int i = 1; i <= a; i += 2)
    			printf("%d ", i);
    		puts("");
    		for (int i = 2; i <= a; i += 2)
    			printf("%d ", i);
    		puts("");
    	}
    }

    13、

    Fibonacci数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    无穷数列1,1,2,3,5,8,13,21,34,55...称为Fibonacci数列,它可以递归地定义为
    F(n)=1 ...........(n=1或n=2)
    F(n)=F(n-1)+F(n-2).....(n>2)
    现要你来求第n个斐波纳奇数。(第1个、第二个都为1)
    输入
    第一行是一个整数m(m<5)表示共有m组测试数据
    每次测试数据只有一行,且只有一个整形数n(n<20)
    输出
    对每组输入n,输出第n个Fibonacci数
    样例输入
    3
    1
    3
    5
    样例输出
    1
    2
    5
    来源
    经典题目
    上传者
    张云聪
    #include <stdio.h>
    int F(int n) {
    	if (n == 1 || n == 2) {
    		return 1;
    	} else {
    		return F(n - 1) + F(n - 2);
    	}
    }
    
    int main() {
    	int i, n;
    	scanf("%d", &i);
    	while (i--) {
    		scanf("%d", &n);
    		printf("%d
    ", F(n));
    	}
    	return 0;
    }
    
    #include<stdio.h>//最优程序
    main()
    {
    	int m,n,i,s1,s2;
    	scanf("%d",&m);
    	while(m--)
    	{	scanf("%d",&n);
    		for(i=3,s1=s2=1;i<=n;i++)
    		{
    			s1=s1+s2;s2=s1-s2;
    		}
    		printf("%d
    ",s1);
    	}
    }

    22、

    素数求和问题

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述
    现在给你N个数(0<N<1000),现在要求你写出一个程序,找出这N个数中的所有素数,并求和。
    输入
    第一行给出整数M(0<M<10)代表多少组测试数据
    每组测试数据第一行给你N,代表该组测试数据的数量。
    接下来的N个数为要测试的数据,每个数小于1000
    输出
    每组测试数据结果占一行,输出给出的测试数据的所有素数和
    样例输入
    3
    5
    1 2 3 4 5
    8
    11 12 13 14 15 16 17 18
    10
    21 22 23 24 25 26 27 28 29 30
    
    样例输出
    10
    41
    52
    
    来源
    [hzyqazasdf]原创
    上传者
    hzyqazasdf
    #include<stdio.h>
    #include<math.h>
    int main() {
    	int i, j, k, a, n, m, sum = 0;
    	scanf("%d", &a);
    	for (i = 0; i < a; i++) {
    		scanf("%d", &n);
    		for (j = 0; j < n; j++) {
    			scanf("%d", &m);
    			for (k = 2; k <= sqrt(m); k++) {
    				if (m % k == 0)
    					break;
    			}
    			if (k > sqrt(m) && m != 1)
    				sum = sum + m;
    		}
    		printf("%d
    ", sum);
    		sum = 0;
    	}
    	return 0;
    }
    
    #include<stdio.h>//最优程序
    #include <math.h>
    int main()
    {
    	int m,n,i,j,a[1000],flag=0;
    	long s;
    	scanf("%d",&m);
    	while(m--)
    	{
    		s=0;
    		scanf("%d",&n);
    		for(i=0;i<n;i++)
    		scanf("%d",&a[i]);
    		for(i=0;i<n;i++)
    		{
    			if(a[i]==1)	continue;
    			flag=0;
    			for(j=2;j<=sqrt(a[i]);j++)
    			{
    				if(a[i]%j==0)
    				{flag=1;break;}			
    			}
    			if(flag==0)	s+=a[i];
    		}
    	printf("%d
    ",s);
    	}
    	return 0;
    }        

    24、

    素数距离问题

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述
    现在给出你一些数,要求你写出一个程序,输出这些整数相邻最近的素数,并输出其相距长度。如果左右有等距离长度素数,则输出左侧的值及相应距离。
    如果输入的整数本身就是素数,则输出该素数本身,距离输出0
    输入
    第一行给出测试数据组数N(0<N<=10000)
    接下来的N行每行有一个整数M(0<M<1000000),
    输出
    每行输出两个整数 A B.
    其中A表示离相应测试数据最近的素数,B表示其间的距离。
    样例输入
    3
    6
    8
    10
    样例输出
    5 1
    7 1
    11 1
    来源
    经典题目
    上传者
    hzyqazasdf
     
    #include<stdio.h>
    #include<math.h>
    bool judge(int m);
    int main()
    {
        int N,n,i;
        scanf("%d",&N);
        while(N--)
        {
            scanf("%d",&n);
            if(judge(n))
            {
                printf("%d 0
    ",n);
                continue;
            }
            for(i=1; n-i!=-1; i++)
            {
                if(judge(n-i))
                {
                    printf("%d %d
    ",n-i,i);
                    break;
                }
                if(judge(n+i))
                {
                    printf("%d %d
    ",n+i,i);
                    break;
                }
            }
        }
        return 0;
    }
    bool judge(int m)
    {
        if(m==0||m==1)
            return false;
        int i;
        for(i=2; i<=sqrt(m); i++)
        {
            if(m%i==0)break;
        }
        if(i>sqrt(m))
            return true;
        return false;
    }
     
    #include<iostream>//最优程序
    #include<cmath>
    using namespace std;
    
    bool isprime(int n)
    {
    	for(int k=2;k<=sqrt((double)n);k++)
    		if((n%k)==0)
    			return false;
    	return true;
    }
    int main()
    {
    	int n;
    	cin>>n;
    	while(n--)
    	{
    		int num,i,j;		
    		cin>>num;
    		if(num==1)
    		{
    			cout<<"2 1"<<endl;
    			continue;
    		}
    		for(i=num;!isprime(i);i--);	
    		for(j=num;!isprime(j);j++);	
    		
    		if((num-i)<(j-num))
    			cout<<i<<' '<<(num-i)<<endl;
    		else if((num-i)>(j-num))
    			cout<<j<<' '<<(j-num)<<endl;
    		else if((num-i)==(j-num))
    			cout<<i<<' '<<(num-i)<<endl;
    	}
    }                

    25、

    A Famous Music Composer

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    Mr. B is a famous music composer. One of his most famous work was his set of preludes. These 24 pieces span the 24 musical keys (there are musically distinct 12 scale notes, and each may use major or minor tonality). The 12 distinct scale notes are: 
     A     A#=Bb  B        C       C#=Db D       D#=Eb  E       F        F#=Gb  G       G#=Ab
     
    Five of the notes have two alternate names, as is indicated above with equals sign. Thus, there are 17 possible names of scale notes, but only 12 musically distinct notes. When using one of these as the keynote for a musical key, we can further distinguish between major and minor tonalities. This gives 34 possible keys, of which 24 are musically distinct. 
    In naming his preludes, Mr. B used all the keys except the following 10, which were named instead by their alternate names: 
     Ab minor  A# major A# minor  C# major  Db minor
     D# major  D# minor Gb major  Gb minor  G# major 
    Write a program that, given the name of a key, give an alternate name if it has one, or report the key name is unique. 
    输入
    Each test case is described by one line having the format "note tonality", where "note" is one of the 17 names for the scale notes given above, and "tonality" is either "major" or "minor" (quotes for clarify).
    输出
    For each case output the required answer, following the format of the sample.
    样例输入
    Ab minor
    D# major
    G minor
    样例输出
    Case 1: G# minor
    Case 2: Eb major
    Case 3: UNIQUE
    来源
    hdu
    上传者
    李如兵
     
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    char str[100];
    int cas = 1;
    
    int main()
    {
        while(gets(str))
        {
            printf("Case %d: ",cas++);
            int i,j,len;
            len = strlen(str);
            if(str[1] == ' ')
                printf("UNIQUE
    ");
            else
            {
                if(str[1] == '#')
                {
                    if(str[0] == 'G')
                        printf("Ab");
                    else
                        printf("%cb",str[0]+1);
                }
                else if(str[1] == 'b')
                {
                    if(str[0] == 'A')
                    printf("G#");
                    else
                    printf("%c#",str[0]-1);
                }
                for(i = 2;i<len;i++)
                printf("%c",str[i]);
                printf("
    ");
            }
        }
    
        return 0;
    }
     
    #include<iostream>//最优程序
    #include<string>
    using namespace std;
    string trans(string a){
    	string b="";
    	if(a[1]=='#'){
    		b+=char((a[0]-'A'+1)%7+'A');
    		b+='b';
    	}else{
    		b+=char((a[0]-'A'+6)%7+'A');
    		b+='#';
    	}
    	return b;
    }
    int main(){
    	string a,b;
    	for(int t=1; cin>>a>>b; t++){
    		cout<<"Case "<<t<<": ";
    		if(a.length()==1)
    			cout<<"UNIQUE"<<endl;
    		else
    			cout<<trans(a)<<" "<<b<<endl;
    	}
    	return 0;
    }
            

    31、

    5个数求最值

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    设计一个从5个整数中取最小数和最大数的程序
    输入
    输入只有一组测试数据,为五个不大于1万的正整数
    输出
    输出两个数,第一个为这五个数中的最小值,第二个为这五个数中的最大值,两个数字以空格格开。
    样例输入
    1 2 3 4 5
    样例输出
    1 5
    来源
    C语言课本第四章第一题
    上传者
    张云聪
    #include<stdio.h>
    int main() {
    	int a[5], temp, i, j;
    	for (i = 0; i < 5; i++)
    		scanf("%d", &a[i]);
    	for (j = 0; j < 5; j++)
    		for (i = 0; i < 4; i++)
    			if (a[i] > a[i + 1]) {
    				temp = a[i];
    				a[i] = a[i + 1];
    				a[i + 1] = temp;
    			}
    	printf("%d %d", a[0], a[4]);
    	return 0;
    }
     
    #include<iostream>//最优程序
    #include<iterator>
    #include<algorithm>
    using namespace std;
    int main()
    {
        int a[5];
        copy(istream_iterator<int>(cin),istream_iterator<int>(),a);
        cout<<*min_element(a,a+5)<<" "<<*max_element(a,a+5)<<endl;
    }        
    
    

    33、

    蛇形填数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:3
    描述
    在n*n方陈里填入1,2,...,n*n,要求填成蛇形。例如n=4时方陈为:
    10 11 12 1
    9 16 13 2
    8 15 14 3
    7 6 5 4
    输入
    直接输入方陈的维数,即n的值。(n<=100)
    输出
    输出结果是蛇形方陈。
    样例输入
    3
    样例输出
    7 8 1
    6 9 2
    5 4 3
    来源
    算法经典
    上传者
    首席执行官
     
    #include"stdio.h"
    #include<stdlib.h>
    int main()
    {
        int a[109][109]= {0},i,j,k,n,m,top,x,y;
        top=1;
        scanf("%d",&n);
        a[x=0][y=n-1]=1;
        while(top<n*n)
        {
            while(x+1<n&&!a[x+1][y]) a[++x][y]=++top;
            while(y-1>=0&&!a[x][y-1]) a[x][--y]=++top;
            while(x-1>=0&&!a[x-1][y]) a[--x][y]=++top;
            while(y+1<n&&!a[x][y+1]) a[x][++y]=++top;
        }
    
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
    
                printf("%d ",a[i][j]);
            printf("
    ");
        }
        //system("33.exe
    ");
    }
     
    #include<stdio.h>//最优程序
    int main()
    {
        int a,b,c,d,n,sum=1;
        int yi[101][101];
        scanf("%d",&n);
        for(a=0;a<=(n-1)/2;a++)
        {
            for(b=a;b<=n-a-1;b++)
                yi[b][n-a-1]=sum++;
            for(b=n-2-a;b>=a;b--)
                yi[n-a-1][b]=sum++;
            for(b=n-a-2;b>=a;b--)
                yi[b][a]=sum++;
            for(b=a+1;b<n-a-1;b++)
                yi[a][b]=sum++;
        }
        for(c=0;c<n;c++)
        {
            for(d=0;d<n;d++)
                printf("%d ",yi[c][d]);
            printf("
    ");
        }
    }        
            

    34、

    韩信点兵

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    相 传韩信才智过人,从不直接清点自己军队的人数,只要让士兵先后以三人一排、五人一排、七人一排地变换队形,而他每次只掠一眼队伍的排尾就知道总人数了。输 入3个非负整数a,b,c ,表示每种队形排尾的人数(a<3,b<5,c<7),输出总人数的最小值(或报告无解)。已知总人数不小于10,不超过100 。
    输入
    输入3个非负整数a,b,c ,表示每种队形排尾的人数(a<3,b<5,c<7)。例如,输入:2 4 5
    输出
    输出总人数的最小值(或报告无解,即输出No answer)。实例,输出:89
    样例输入
    2 1 6
    样例输出
    41
    来源
    经典算法
    上传者
    首席执行官
     
     
    #include<iostream>
    using namespace std;
    int main()
    {
    	int a,b,c;
    	cin>>a>>b>>c;
    	int n=(a*70+b*21+c*15)%105;
    	if(n>100||n<10) cout<<"No answer"<<endl;
    	else cout<<n<<endl;
    }   
                  

    39、

    水仙花数

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述
    请判断一个数是不是水仙花数。
    其中水仙花数定义各个位数立方和等于它本身的三位数。
    输入
    有多组测试数据,每组测试数据以包含一个整数n(100<=n<1000)
    输入0表示程序输入结束。
    输出
    如果n是水仙花数就输出Yes
    否则输出No
    样例输入
    153
    154
    0
    样例输出
    Yes
    No
    来源
    C语言课本习题改编
    上传者
    张云聪
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
        int n=0;
        //freopen("input.txt","r",stdin);
        while(scanf("%d",&n)==1)
        {
            if(n!=0)
            {
                if (n==153||n==370||n==371||n==407) printf("Yes
    ");
                else printf("No
    ");
            }
        }
        return 0;
    }
      
    #include<iostream>//最优程序
    using namespace std;
    int main()
    {
        int a;
        while(1)
        {
            cin>>a;
            if(a==0) break;
            cout<<((a==153||a==370||a==371||a==407)?"Yes":"No")<<endl;
        }
    }        
           

    40、

    公约数和公倍数

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    小明被一个问题给难住了,现在需要你帮帮忙。问题是:给出两个正整数,求出它们的最大公约数和最小公倍数。
    输入
    第一行输入一个整数n(0<n<=10000),表示有n组测试数据;
    随后的n行输入两个整数i,j(0<i,j<=32767)。
    输出
    输出每组测试数据的最大公约数和最小公倍数
    样例输入
    3
    6 6
    12 11
    33 22
    
    样例输出
    6 6
    1 132
    11 66
    来源
    [苗栋栋]原创
    上传者
    苗栋栋
    #include<stdio.h>
    int main() {
    	int a, b, c, n, k;
    	scanf("%d", &n); //输入一个整数n(0<n<=10000),表示有n组测试数据 
    	while (n--) {
    		scanf("%d %d", &a, &b); //输入两个整数 
    		k = a * b;
    		while (b != 0) {
    			c = a % b;
    			a = b;
    			b = c;
    		}
    		printf("%d %d
    ", a, k / a);
    	}
    	return 0;
    }
     
    import java.io.*;
    import java.util.*;
    
    public class Main {
    
        public static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }
    
        public static Scanner count = new Scanner(System.in);
    
        public static void main(String[] arges) {
            int n = count.nextInt();
            while ((n--) > 0) {
                int a = count.nextInt(), b = count.nextInt();
                System.out.println(gcd(a, b) + " " + a * b / gcd(a, b));
            }
            count.close();
        }
    }
            
     
    #include<stdio.h>
    int main()
    {
        unsigned int u,v,r,s,i,d;
        scanf("%u",&s);
        for(i=1;i<=s;i++)
        {
            scanf("%u%u",&u,&v);
            d=u*v;
            while(v!=0)
            {
                r=u%v;
                u=v;
                v=r;
            }
            printf("%u %u
    ",u,d/u);
        }
        return 0;
    }        
    

    41、

    三个数从小到大排序

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:0
    描述

    现在要写一个程序,实现给三个数排序的功能

    输入
    输入三个正整数
    输出
    给输入的三个正整数排序
    样例输入
    20 7 33
    样例输出
    7 20 33
    来源
    [张洁烽]原创
    上传者
    张洁烽
    import java.util.Scanner;
    
    public class Main
    {
    public static void main(String[] args)
    	{
    		int a,b,c,n;
    		Scanner num=new Scanner(System.in);
    		System.out.print("");
    		a=num.nextInt();
    		System.out.print("");
    		b=num.nextInt();
    		System.out.print("");
    		c=num.nextInt();
    		if(a>b) {
    			n=a;a=b;b=n;
    		}
    
    		if(b>c) {
    			n=b;b=c;c=n;
    		}
    		if(a>c) {
    			n=a;a=c;c=n;
    		}
    		System.out.println(a+" "+b+" "+c);
    	}
    }
     
    #include <stdio.h>//最优程序
    int main()
    {
        int a,b,c,an[3],i,t,j,max,flag;
        scanf ("%d %d %d",&an[0],&an[1],&an[2]);
        for (i=0;i<3;i++)
        {
            t=max=an[i];
            flag=i;
            for (j=i;j<3;j++)
                if (an[j]>t) 
                {
                    max=an[j];
                    flag=j;
                };
            t=an[i];
            an[i]=max;
            an[flag]=t;
        }
        for (i=2;i>=0;i--)
            printf ("%d ",an[i]);
        return 0;
    }
           
    

    56、

    阶乘因式分解(一)

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述
    输入
    第一行是一个整数s(0<s<=100),表示测试数据的组数
    随后的s行, 每行有两个整数n,m。
    输出
    输出m的个数。
    样例输入
    2
    100 5
    16 2
    
    样例输出
    24
    15
    
    来源
    网络
    上传者
    苗栋栋
    #include <stdio.h>
    int main(void) {
    	int N, n, m, count;
    	scanf("%d", &N);
    	while (N--) {
    		count = 0;
    		scanf("%d%d", &n, &m);
    		while (n) {
    			n = n / m;
    			count = count + n;
    		}
    		printf("%d
    ", count);
    
    	}
    	return 0;
    }
     
    #include<iostream>//最优程序
    using namespace std;
    int get(int n,int num)
    {
        if(n==0) return 0;
        else return get(n/num,num)+n/num;
    }
    int main()
    {
        int n;
        cin>>n;
        while(n--)
        {
            int a,b;
            cin>>a>>b;
            cout<<get(a,b)<<endl;
        }
    }        
    

    57、

    6174问题

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:2
    描述

    假 设你有一个各位数字互不相同的四位数,把所有的数字从大到小排序后得到a,从小到大后得到b,然后用a-b替换原来这个数,并且继续操作。例如,从 1234出发,依次可以得到4321-1234=3087、8730-378=8352、8532-2358=6174,又回到了它自己!现在要你写一个 程序来判断一个四位数经过多少次这样的操作能出现循环,并且求出操作的次数

    比如输入1234执行顺序是1234->3087->8352->6174->6174,输出是4

    输入
    第一行输入n,代表有n组测试数据。
    接下来n行每行都写一个各位数字互不相同的四位数
    输出
    经过多少次上面描述的操作才能出现循环
    样例输入
    1
    1234
    样例输出
    4
    来源
    [张洁烽]原创
    上传者
    张洁烽
     
    #include<stdio.h>
    int main()
    {
        int n,m,a[4],i,j,count,max,min,t;
        scanf("%d",&n);
        while(n--)
        {
            count=1;
            scanf("%d",&m);
            while(m!=6174)
            {
                for(i=0; i<4; i++)
                {
                    a[i]=m%10;
                    m=m/10;
                }
                for(i=0; i<4; i++)
                    for(j=i+1; j<4; j++)
                        if(a[i]<a[j])
                        {
                            t=a[i];
                            a[i]=a[j];
                            a[j]=t;
                        }
                max=a[0]*1000+a[1]*100+a[2]*10+a[3];
                min=a[3]*1000+a[2]*100+a[1]*10+a[0];
                m=max-min;
                count++;
            }
            printf("%d
    ",count);
        }
        return 0;
    }
      
    #include<iostream>//最优程序
    #include<algorithm>
    #include<stdio.h>
    using namespace std;
    int main()
    {
        //freopen("1.txt","r",stdin);
        int k;
        cin>>k;
        while(k--)
        {
            int n,a[4],n1,n2;
            scanf("%d",&n);
            int s=1;
            while(n!=6174)
            {
                a[0]=n%10;
                a[3]=n/1000;
                a[1]=n/10%10;
                a[2]=n/100%10;
                sort(a,a+4);
                n1=1000*a[3]+100*a[2]+10*a[1]+a[0];
                n2=1000*a[0]+100*a[1]+10*a[2]+a[3];
                n=n1-n2;
                s++;
            }
            printf("%d
    ",s);
        }
    }        
           

    60、

    谁获得了最高奖学金

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:2
    描述
        某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同:
      1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得;
      2) 五四奖学金,每人4000元,期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生均可获得;
      3) 成绩优秀奖,每人2000元,期末平均成绩高于90分(>90)的学生均可获得;
      4) 西部奖学金,每人1000元,期末平均成绩高于85分(>85)的西部省份学生均可获得;
      5) 班级贡献奖,每人850元,班级评议成绩高于80分(>80)的学生干部均可获得;
      只要符合条件就可以得奖,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。例如姚林的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。
      现在给出若干学生的相关数据,请计算哪些同学获得的奖金总数最高(假设总有同学能满足获得奖学金的条件)。
    输入
    第 一行输入数据N,表示测试数据组数(0<N<100),每组测试数据输入的第一行是一个整数X(1 <= X <= 100),表示学生的总数。接下来的X行每行是一位学生的数据,从左向右依次是姓名,期末平均成绩,班级评议成绩,是否是学生干部,是否是西部省份学生, 以及发表的论文数。姓名是由大小写英文字母组成的长度不超过20的字符串(不含空格);期末平均成绩和班级评议成绩都是0到100之间的整数(包括0和 100);是否是学生干部和是否是西部省份学生分别用一个字符表示,Y表示是,N表示不是;发表的论文数是0到10的整数(包括0和10)。每两个相邻数 据项之间用一个空格分隔。
    输出
      每组测试数据输出包括三行,第一行是获得最多奖金的学生的姓名,第二行是这名学生获得的奖金总数。如果有两位或两位以上的学生获得的奖金最多,输出他们之中在输入文件中出现最早的学生的姓名。第三行是这X个学生获得的奖学金的总数。
    样例输入
    1
    4
    YaoLin 87 82 Y N 0
    ChenRuiyi 88 78 N Y 1
    LiXin 92 88 N N 0
    ZhangQin 83 87 Y N 1
    样例输出
    ChenRuiyi
    9000
    28700
    来源
    NOIP2005
    上传者
    hzyqazasdf
     
    #include <iostream>
    using namespace std;
    int main(void)
    {
       string str,_str;
       char ca,cb;
       int n,m,x,y,z,s,sum,max;
       cin>>n;
       while(n--)
       {
       	  cin>>m;
       	  max = sum = 0;
       	  while(m--)
       	  { 
       	    s = 0;
       	  	cin>>str>>x>>y>>ca>>cb>>z;
       	  	if(x>80&&z>0)
       	  	{
    	  	   	s += 8000;
    	  	   	sum += 8000;
            }
            if(x>85&&y>80)
            {
            	s += 4000;
            	sum += 4000;
            }
            if(x>90)
            {
            	s += 2000;
            	sum += 2000;
            }
            if(x>85&&cb == 'Y')
            {
            	s += 1000;
            	sum += 1000;
            }
            if(y>80&&ca == 'Y')
            {
            	s += 850;
            	sum += 850;
            }
            if(max < s)
            {
            	max = s;
            	_str = str;
            }
          }
          cout<<_str<<endl<<max<<endl<<sum<<endl;
       }	
    }  
     
    #include<iostream>//最优程序
    #include<string>
    #include<algorithm>
    #include<numeric>
    using namespace std;
    int calc(int qm,int py,bool gb,bool xb,bool lw)
    {
        int all=0;
        if(qm>80 && lw) all+=8000;
        if(qm>85&& py>80) all+=4000;
        if(qm>90) all+=2000;
        if(xb&&qm>85) all+=1000;
        if(gb&&py>80) all+=850;
        return all;
    }
    
    int main()
    {
        int n;
        cin>>n;
        while(n--)
        {
            int m;
            cin>>m;
            int max_num=0,all=0;
            string max_stu;
            while(m--)
            {
                int qm,py,lw;
                string xm,gbs,xbs;
                cin>>xm>>qm>>py>>gbs>>xbs>>lw;
                bool gb=gbs=="Y",xb=xbs=="Y";
                int num=calc(qm,py,gb,xb,lw>0);
                all+=num;
                if(num>max_num) {max_num=num;max_stu=xm;}
            }
            cout<<max_stu<<endl<<max_num<<endl<<all<<endl;
        }
    }        
                  

    62、

    笨小熊

    时间限制:2000 ms  |  内存限制:65535 KB
    难度:2
    描述

    笨小熊的词汇量很小,所以每次做英语选择题的时候都很头疼。但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大!
    这种方法的具体描述如下:假设maxn是单词中出现次数最多的字母的出现次数,minn是单词中出现次数最少的字母的出现次数,如果maxn-minn是一个质数,那么笨小熊就认为这是个Lucky Word,这样的单词很可能就是正确的答案。

    输入
    第一行数据N(0<N<100)表示测试数据组数。
    每组测试数据输入只有一行,是一个单词,其中只可能出现小写字母,并且长度小于100。
    输出
    每组测试数据输出共两行,第一行是一个字符串,假设输入的的单词是Lucky Word,那么输出“Lucky Word”,否则输出“No Answer”;
    第二行是一个整数,如果输入单词是Lucky Word,输出maxn-minn的值,否则输出0
    样例输入
    2
    error
    olympic
    样例输出
    Lucky Word
    2
    No Answer
    0
    来源
    NOIP2008
    上传者
    hzyqazasdf
     
    #include<iostream>
    #include<string>
    using namespace std;
    int prime_number(int n)
    {
        if(n==1||n==0)return 0;
        if(n==2)return 1;
        else
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)return 0;
        }
        return 1;
    }
    
    int maxn_minn(string a)
    {
        int b[101]={0};
        for(int i=0; i<a.size(); i++)
                for(int j=0; j<a.size(); j++)
                {
                    if(a[i]==a[j])
                        b[i]++;
                }
                int maxn=b[0];
                int minn=b[0];
                for(int i=0;i<a.size();i++)
                {
                    if(b[i]>maxn)maxn=b[i];
                    if(b[i]<minn)minn=b[i];
                }
                return maxn-minn;
    }
    
    int main()
    {
        int n;
        cin>>n;
        while(n--)
        {
            string a;
            cin>>a;
            prime_number(maxn_minn(a))==1?cout<<"Lucky Word
    "<<maxn_minn(a)<<endl:cout<<"No Answer
    "<<"0"<<endl;
        }
        return 0;
    }
      
    #include<iostream>//最优程序
    #include<string>
    #include<algorithm>
    #include<numeric>
    using namespace std;
    
    bool isPrime(int n)
    {
        if(n==0) return false;
        if(n==1) return false;
        if(n==2) return true;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0) return false;
        }
        return true;
    
    }
    int min_e(int *p,int *q)
    {
        int m=1000;
        for(int* i=p;i!=q;i++)
        {
            if(*i<m && *i!=0) m=*i;
        }
        return m;
    }
    int main()
    {
            int n;
        string str;
        cin>>n;
        while(n--)
        {
            int count[26]={0};
            cin>>str;
            for(int i=0;i!=str.size();++i)
            {
                ++count[str[i]-'a'];
            }
            int nn=*max_element(count,count+26)-min_e(count,count+26);
            if(isPrime(nn)) cout<<"Lucky Word"<<endl<<nn<<endl;
            else cout<<"No Answer"<<endl<<0<<endl;
    
        }
    }        
           

    64、

    鸡兔同笼

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡和兔的数目,如果无解,则输出“No answer”(不要引号)。
    输入
    第一行输入一个数据a,代表接下来共有几组数据,在接下来的(a<10)
    a行里,每行都有一个n和m.(0<m,n<100)
    输出
    输出鸡兔的个数,或者No answer
    样例输入
    2
    14 32
    10 16
    
    样例输出
    12 2
    No answer
    来源
    [张洁烽]原创
    上传者
    张洁烽
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
    	int i,m,n,N;
    	scanf("%d",&N);
    	while(N--)
    	{
    		int x,y,a=0;
    		scanf("%d%d",&n,&m);
    		for(i=0;i<=n;i++)
    		{
    			if(i*2+(n-i)*4==m)
                {
                 a=1;
                printf("%d %d
    ",i,n-i);break;
                }
    		}
    		if(a==0)printf("No answer
    ");
    	}
    	return 0;
    } 
     
    #include<iostream>//最优程序
    using namespace std;
    int main()
    {
       int n,a,b,p,q;
       cin>>n;
       while(n--)
       {
          cin>>a>>b;
          q=(b-2*a)/2;
          p=a-q;
          if(p<0 ||q<0 || b%2) cout<<"No answer"<<endl;
          else cout<<p<<" "<<q<<endl;
       }
    }                        
           

    65、

    另一种阶乘问题

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    大家都知道阶乘这个概念,举个简单的例子:5!=1*2*3*4*5.现在我们引入一种新的阶乘概念,将原来的每个数相乘变为i不大于n的所有奇数相乘例如:5!!=1*3*5.现在明白现在这种阶乘的意思了吧!

    现在你的任务是求出1!!+2!!......+n!!的正确值(n<=20)

    输入
    第一行输入一个a(a<=20),代表共有a组测试数据
    接下来a行各行输入一个n.
    输出
    各行输出结果一个整数R表示1!!+2!!......+n!!的正确值
    样例输入
    2
    3
    5
    样例输出
    5
    23
    来源
    [张洁烽]原创
    上传者
    张洁烽
     
    #include <stdio.h>
    int f(int n) {
        int i, s = 1;
        for (i = 1; i <= n; i += 2)
            s *= i;
        return s;
    }
    int main() {
        int a, n, i, s;
        scanf("%d", &a);
        while (a--) {
            s = 0;
            scanf("%d", &n);
            for (i = 1; i <= n; i++)
                s += f(i);
            printf("%d
    ", s);
        }
        return 0;
    }    
     
    /*
    #include<iostream>
    using namespace std;
    int f(int n)
    {
        if(n%2) return n==1?1:n*f(n-2);
        return f(n-1);
    }
    int g(int n)
    {
        return n?g(n-1)+f(n):0;
    }
    int main()
    {
        int n,m;
        cin>>n;
        while(n--)
        {
            cin>>m;
            cout<<g(m)<<endl;
        }
    }*/
    #include<iostream>//最优程序
    using namespace std;
    int main()
    {
        int n,m,r[]={0,1,2,5,8,23,38,143,248,1193,2138,12533,22928,158063,293198,2320223,4347248,38806673,73266098,727995173,1382724248};
        cin>>n;
        while(n--)
        {
            cin>>m;
            cout<<r[m]<<endl;
        }
    }        
      

    72、

    Financial Management

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.
    输入
    The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.
    输出
    The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.
    样例输入
    100.00
    489.12
    12454.12
    1234.10
    823.05
    109.20
    5.27
    1542.25
    839.18
    83.99
    1295.01
    1.75
    
    样例输出
    1581.42
    来源
    [张洁烽]原创
    上传者
    张洁烽
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
        double sum=0,a;
        int n=12;
       // freopen("input.txt","r",stdin);
        while(n--)
        {
            scanf("%lf",&a);
            sum+=a;
        }
        printf("%.2lf
    ",sum/12);
        return 0;
    }
       
    #include<iostream>//最优程序
    #include<iomanip>
    using namespace std;
    
    int main()
    {
        double sum=0,a;
        for(int i=0;i<12;i++)
        {
            cin>>a;
            sum+=a;
        }
        cout<<fixed<<setprecision(2)<<sum/12.0<<endl;
    }        
          

    74、

    小学生算术

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    很多小学生在学习加法时,发现“进位”特别容易出错。你的任务是计算两个三位数在相加时需要多少次进位。你编制的程序应当可以连续处理多组数据,直到读到两个0(这是输入结束标记)。
    输入
    输入两个正整数m,n.(m,n,都是三位数)
    输出
    输出m,n,相加时需要进位多少次。
    样例输入
    123 456
    555 555
    123 594
    0 0
    样例输出
    0
    3 
    1
    
    来源
    [张洁烽]原创
    上传者
    张洁烽
     
    #include <stdio.h>
    int main()
    {
        int m,n,i,j;
        int a[3],b[3];
        while(scanf("%d%d",&m,&n),m!=0||n!=0)
        {
            a[0]=m/100;
            a[1]=(m-100*a[0])/10;
            a[2]=m%10;
            b[0]=n/100;
            b[1]=(n-100*b[0])/10;
            b[2]=n%10;
            j=0;
            for(i=2; i>=0; i--)
            {
                if(a[i]+b[i]>=10)
                {
                    j++;
                    a[i-1]+=1;//要考虑进位问题
                }
            }
            printf("%d
    ",j);
        }
        return 0;
    }   
     
     
    #include<stdio.h>
    int main()
    {
        int a,b,c,d,e,f,n,m,i;
        for(;;)
        {
            scanf("%d%d",&n,&m);
            if(n==0&&m==0)
                return 0;
            else
            {
                i=0;
                a=n/100;b=n%100/10;c=n%10;
                d=m/100;e=m%100/10;f=m%10;
                if(c+f>=10)
                {i+=1;b+=1;}
                if(b+e>=10)
                {i+=1;a+=1;}
                if(a+d>=10)
                {i+=1;}
                printf("%d
    ",i);
            }
        }
      return 0;
    }
                  
         

    75、

    日期计算

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    如题,输入一个日期,格式如:2010 10 24 ,判断这一天是这一年中的第几天。
    输入
    第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每行的输入数据都是一个按题目要求格式输入的日期。
    输出
    每组输入数据的输出占一行,输出判断出的天数n
    样例输入
    3
    2000 4 5
    2001 5 4
    2010 10 24
    样例输出
    96
    124
    297
    来源
    [naonao]改编C语言习题
    上传者
    naonao
     
    #include <iostream>
    using namespace std;
    int leap(int a)
    {
    	if(a%4==0&&a%100!=0||a%400==0)
    		return 1;
    	else return 0;
    }
    int number(int year,int m,int d)
    {
    	int sum=0,i,j,k,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    	int b[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    	if(leap(year)==1)
    		for(i=0;i<m-1;i++)
    			sum+=b[i];
    	else 
    		for(i=0;i<m-1;i++)
    		    sum+=a[i];
    		    sum+=d;
    		return sum; 
    }
    int main(int argc, char const *argv[])
    {
    	int n;
    	cin>>n;
    	while(n--)
    	{
    		int year,month,day,n;
    		cin>>year>>month>>day;
    		n=number(year,month,day);
    		cout<<n<<endl;
    	}
    	return 0;
    }   
     
    #include<stdio.h>//最优程序
    int main()
    {
        int a,b=0,c,y,m,d,fib;
        scanf("%d",&a);
        while(a--)
        {
            scanf("%d %d %d",&y,&m,&d);
            if(y%400==0||y%100!=0&&y%4==0)
                fib=29;
            else fib=28;
            for(c=1;c<=m;c++)
            switch(c-1)
            {
               case 1:
               case 3:
               case 5:
               case 7:
               case 8:
               case 10:b+=31;break;
               case 2:b+=fib;break;
               case 4:
               case 6:
               case 9:
               case 11:b+=30;break;
            }
            b+=d;
            printf("%d
    ",b);
            b=0;
        }
        return 0;
    }        
         

    77、

    开灯问题

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    有 n盏灯,编号为1~n,第1个人把所有灯打开,第2个人按下所有编号为2 的倍数的开关(这些灯将被关掉),第3 个人按下所有编号为3的倍数的开关(其中关掉的灯将被打开,开着的灯将被关闭),依此类推。一共有k个人,问最后有哪些灯开着?输入:n和k,输出开着的 灯编号。k≤n≤1000

    输入
    输入一组数据:n和k
    输出
    输出开着的灯编号
    样例输入
    7 3
    样例输出
    1 5 6 7
    来源
    经典算法
    上传者
    首席执行官
     
    #include<stdio.h>
    int main( )
    {
        int n, k, j, open,i;
        scanf("%d%d", &n, &k );
        for(i = 1 ; i <= n ; i++ )
        {
            open = 1;
            for( j = 2 ; j <= k ; j++ )
            {
                if( i % j == 0 )
                    open = (open+1) % 2;
            }
            if( open )
                printf("%d ", i );
        }
        return 0;
    }  
     
    #include <iostream>//最优程序
    using namespace std;
    int main()
    {
        int n,k,a[1000],i;
        cin>>n>>k;
        for(i=0;i<n;i++)
            a[i]=1;
        for(i=2;i<=k;i++)
            for(int j=0;j<n;j++)
            {
                if((j+1)%i==0)
                if(a[j]==0)a[j]=1;
                else a[j]=0;
            }
            for(i=0;i<n;i++)
                if(a[i]==1)cout<<i+1<<" ";
                cout<<endl;
        return 0;
    }              

    94、

    cigarettes

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述

    Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them

    one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.
    Now,do you know how many cigarettes can Tom has?

    输入
    First input is a single line,it's n and stands for there are n testdata.then there are n lines ,each line contains two integer numbers giving the values of n and k.
    输出
    For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have.
    样例输入
    3
    4 3
    10 3
    100 5
    样例输出
    5
    14
    124
    来源
    [rooot]原创
    上传者
    rooot
     
    #include<iostream>
    using namespace std;
    int main()
    {
        int n;cin>>n;
        while(n--)
        {
            int a,b;
            cin>>a>>b;
            int sum=0;
            sum+=a;
            while(a>=b)
            {
                a-=b;//只要a-b还大于b , 就相当于a会多一个
                a++;
                sum++;
            }
            cout<<sum<<endl;
        }
        return 0;
    }
       
    #include "stdio.h"
    #include<fstream>
    int main()
    {
        //freopen("d:\1.txt","r",stdin);
        //freopen("d:\2.txt","w",stdout);
        int m;
        scanf("%d",&m);
        while(m--)
        {
            int n,k,sum;
            scanf("%d%d",&n,&k);
            sum=n;
            while(n/k)                   
            { sum+=n/k;  n=n/k+n%k; }
            printf("%d
    ",sum);
        }
        return 0;
    }              

    96、

    n-1位数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    已知w是一个大于10但不大于1000000的无符号整数,若w是n(n≥2)位的整数,则求出w的后n-1位的数。

    输入
    第一行为M,表示测试数据组数。
    接下来M行,每行包含一个测试数据。
    输出
    输出M行,每行为对应行的n-1位数(忽略前缀0)。如果除了最高位外,其余位都为0,则输出0。
    样例输入
    4
    1023
    5923
    923
    1000
    样例输出
    23
    923
    23
    0
    来源
    [rooot]原创
    上传者
    rooot
     
    #include<stdio.h><pre name="code" class="cpp">//较简单的做法    
    int main()
    {
        int num;
        int M;
        scanf("%d",&num);
        while(num--)
        {
            scanf("%d",&M);
            int i=10;
            while(M/i>=10)
            {
                i=i*10;
            }
            printf( "%d
    " ,M%i);
        }
    }  
     
    #include<cstdio>//最优程序
    int main()
    {
        int n,m;
        scanf("%d",&n);
        while(n--)
        {
            scanf("
    %*c%d",&m);
            printf("%d
    ",m);
        }
    }                
      

    97、

    兄弟郊游问题

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述
    兄弟俩骑车郊游,弟弟先出发,每分钟X米,M分钟后,哥哥带一条狗出发。以每分钟Y米的速度去追弟弟,而狗则以每分钟Z米的速度向弟弟跑去,追上弟弟后又立即返回,直到哥哥追上弟弟时,狗跑了多少米?
    输入
    第一行输入一个整数N,表示测试数据的组数(N<100)每组测试数据占一行,是四个正整数,分别为M,X,Y,Z(数据保证X<Y<Z)
    输出
    输出狗跑的路径,结果保留小数点后两位。
    样例输入
    1
    5 10 15 20
    
    样例输出
    200.00
    来源
    经典数学问题
    上传者
    张云聪
     
    #include "stdio.h"
    int main()
    {
    	int n;
    	scanf("%d",&n);
    	while(n--)
    	{
            double m,x,y,z,s;
    		scanf("%lf%lf%lf%lf",&m,&x,&y,&z);
    		s=x*m/(y-x)*z;
    		printf("%.2lf
    ",s);
    	}
        return 0;
    }  
     
    #include<iostream>//最优程序
    #include<stdio.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        while(n--)
        {
            int s,a,b,c;
            cin>>s>>a>>b>>c;
            printf("%.2lf
    ",s*a/(double)(b-a)*c);
        }
    
    }              

    98、

    成绩转换

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    输入一个百分制的成绩M,将其转换成对应的等级,具体转换规则如下:
    90~100为A;
    80~89为B;
    70~79为C;
    60~69为D;
    0~59为E;
    输入
    第一行是一个整数N,表示测试数据的组数(N<10)
    每组测试数据占一行,由一个整数M组成(0<=M<=100)。
    输出
    对于每组输入数据,输出一行。
    样例输入
    2
    97
    80
    样例输出
    A
    B
    来源
    hdu2004
    上传者
    张云聪
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
    	int n,a;
    	scanf("%d",&n);
    	while(n--)
    	{
    		scanf("%d",&a);
    		if(90<=a&&a<=100) printf("A
    ");
    		if(80<=a&&a<=89) printf("B
    ");
    		if(70<=a&&a<=79) printf("C
    ");
    		if(60<=a&&a<=69) printf("D
    ");
    		if(0<=a&&a<=59) printf("E
    ");
    	}
    	return 0;
    }    
     
    #include<iostream>//最优程序
    using namespace std;
    int main()
    {
    int n,s;
    cin>>n;
    while(n--)
    {
    cin>>s;
    switch(s/10)
    {
    case 10:
    case 9:cout<<"A"<<endl;break;
    case 8:cout<<"B"<<endl;break;
    case 7:cout<<"C"<<endl;break;
    case 6:cout<<"D"<<endl;break;
    default:cout<<"E"<<endl;break;
    }
    }
    }        
        

    100、

    1的个数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    小南刚学了二进制,他想知道一个数的二进制表示中有多少个1,你能帮他写一个程序来完成这个任务吗?
    输入
    第一行输入一个整数N,表示测试数据的组数(1<N<1000)
    每组测试数据只有一行,是一个整数M(0=<M<=10000)
    输出
    每组测试输出占一行,输出M的二进制表示中1的个数
    样例输入
    3
    4
    6
    7
    样例输出
    1
    2
    3
    来源
    [张云聪]原创
    上传者
    张云聪
     
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int main(int argc, char const *argv[])
    {
    	int n;
    	cin>>n;
    	while(n--)
    	{
    		int a,i,count=0;
    		cin>>a;
    		while(a)
    		{
    			if(a%2==1) count++;
    			a/=2;
    		}
    		cout<<count<<endl;
    	}
    	return 0;
    }  
     
    #include<stdio.h>//最优程序
    main(){int n,m,s;scanf("%d",&n);while(n--){scanf("%d",&m);s=0;while(m)m&=m-1,s++;printf("%d
    ",s);}}        
          

    101、

    两点距离

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    输入两点坐标(X1,Y1),(X2,Y2)(0<=x1,x2,y1,y2<=1000),计算并输出两点间的距离。
    输入
    第一行输入一个整数n(0<n<=1000),表示有n组测试数据;
    随后每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
    输出
    对于每组输入数据,输出一行,结果保留两位小数。
    样例输入
    2
    0 0 0 1
    0 1 1 0
    样例输出
    1.00
    1.41
    
    来源
    [苗栋栋]原创
    上传者
    苗栋栋
     
    #include<math.h>
    #include<stdio.h>
    int main()
    {
    	int n;
        double l,x1,x2,y1,y2;
        // freopen("input.txt","r",stdin);
        scanf("%d",&n);
        while(n--)
        {
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        l=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        printf("%.2lf
    ",l);
    	}
        return 0;
    } 
     
    #include<iostream>//最优程序
    #include<math.h>
    #include<iomanip>
    using namespace std;
    int main()
    {
        /*freopen("1.txt","r",stdin);
        freopen("2.txt","w",stdout);*/
    
    double x1,x2,y1,y2,m;
    double a;
    cin>>m;
    while(m--)
    {
        cin>>x1>>y1>>x2>>y2;
        a=sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
        cout.setf(ios::fixed); 
        cout<<setprecision(2)<<a<<endl;
    }
    return 0;
    }
           

    111、

    分数加减法

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述
    编写一个C程序,实现两个分数的加减法
    输入
    输入包含多行数据
    每行数据是一个字符串,格式是"a/boc/d"。
    其中a, b, c, d是一个0-9的整数。o是运算符"+"或者"-"。

    数据以EOF结束
    输入数据保证合法
    输出
    对于输入数据的每一行输出两个分数的运算结果。
    注意结果应符合书写习惯,没有多余的符号、分子、分母,并且化简至最简分数
    样例输入
    1/8+3/8
    1/4-1/2
    1/3-1/3
    样例输出
    1/2
    -1/4
    0
    来源
    水题比赛
    上传者
    hzyqazasdf
     
    #include <iostream>
    #include<cstdlib>
    using namespace std;
    int yinshu(int x,int y)
    {
        if(x<y)
        {
            int tmp;
            tmp = x;
            x = y;
            y = tmp;
        }
        if(x%y == 0)
            return abs(y);
        else
            return yinshu(y,x%y);
    }
    
    int main(void)//最优程序
    {
        int a,b,c,d;
        char optr,num;
        while(cin >> a >> num >> b >> optr >> c >> num >> d)
        {
            int x,y;
            switch(optr)
            {
            case '+':
            {
                x = a*d+b*c;
                y = b*d;
                break;
            }
            case '-':
            {
                x = a*d-b*c;
                y = b*d;
                break;
            }
            }
            if(x == 0)
                cout << 0 << endl;
            else if(y/yinshu(x,y) == 1)
                cout << x/yinshu(x,y) << endl;
            else
                cout << x/yinshu(x,y) << "/" << y/yinshu(x,y) << endl;
        }
        return 0;
    }     

    113、

    字符串替换

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述
    编写一个程序实现将字符串中的所有"you"替换成"we"
    输入
    输入包含多行数据

    每行数据是一个字符串,长度不超过1000
    数据以EOF结束
    输出
    对于输入的每一行,输出替换后的字符串
    样例输入
    you are what you do
    样例输出
    we are what we do
    来源
    水题比赛
    上传者
    hzyqazasdf
     
    #include "iostream"
    #include "cstring"
    #include "cstdio"
    using namespace std;
    int main(int argc, char const *argv[])
    {
        char a[1001];
    
        while(gets(a)!=NULL)
        {
            int i,len=0;
            len=strlen(a);
            for(i=0; i<len; i++)
            {
                if(a[i]=='y'&&a[i+1]=='o'&&a[i+2]=='u')
                {
                    cout<<"we";
                    i+=2;
                }
                else cout<<a[i];
            }
            cout<<endl;
        }
        return 0;
    }
       
    #include<algorithm>//最优程序
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    int main()
    {
        string s, s1, s2;
        while(getline(cin,s))
        {
            int flag;
            s1 = "you";
            s2 = "we";
            flag = s.find(s1,0);
            while(flag != string::npos)
            {
                s.replace(flag, 3, s2);
                flag = s.find(s1, flag + 1);
            }
            cout << s << endl;
        }
        return 0;
    }    

    122、

    Triangular Sums

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述

    The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number of points in a triangular array with n points on side. For example T(4):

    X
    X X
    X X X
    X X X X

    Write a program to compute the weighted sum of triangular numbers:

    W(n) = SUM[k = 1…nk * T(k + 1)]

    输入
    The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

    Each dataset consists of a single line of input containing a single integer n, (1 ≤ n ≤300), which is the number of points on a side of the triangle.
    输出
    For each dataset, output on a single line the dataset number (1 through N), a blank, the value of n for the dataset, a blank, and the weighted sum ,W(n), of triangular numbers for n.
    样例输入
    4
    3
    4
    5
    10
    样例输出
    1 3 45
    2 4 105
    3 5 210
    4 10 2145
    来源
    Greater New York 2006
    上传者
    张云聪
     
    #include<iostream>
    using namespace std;
    int main()
    {
        int n,j=1;
        cin>>n;
        while(n--)
        {
            int a,sum=0;
            cin>>a;
            for(int i=1;i<=a;i++)
            sum+=(i*(i+1)*(i+2))/2;
    
            cout<<j++<<" "<<a<<" "<<sum<<endl;
        }
        return 0;
    }
        
     
    #include<iostream>//最优程序
    using namespace std;
    const int M=310;
    int W[M];
    int main()
    {
        
        for(int i=1;i!=M;i++)
            W[i]=W[i-1]+i*(i+1)*(i+2)/2;
        int m,n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>m;
            cout<<i<<" "<<m<<" "<<W[m]<<endl;
        }
    }                
         

    125、

    盗梦空间

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述

    《盗梦空间》是一部精彩的影片,在这部电影里,Cobb等人可以进入梦境之中,梦境里的时间会比现实中的时间过得快得多,这里假设现实中的3分钟,在梦里就是1小时。

    然而,Cobb他们利用强效镇静剂,可以从第一层梦境进入第二层梦境,甚至进入三层,四层梦境,每层梦境都会产生同样的时间加速效果。那么现在给你Cobb在各层梦境中经历的时间,你能算出现实世界过了多长时间吗?

    比如,Cobb先在第一层梦境待了1个小时,又在第二层梦境里待了1天,之后,返回第一层梦境之后立刻返回了现实。

    那么在现实世界里,其实过了396秒(6.6分钟)

    输入
    第一行输入一个整数T(0<=T<=100),表示测试数据的组数。
    每组测试数据的第一行是一个数字M(3<=M<=100)
    随 后的M行每行的开头是一个字符串,该字符串如果是"IN" 则Cobb向更深层的梦境出发了,如果是字符串"OUT"则表示Cobb从深层的梦回到了上一层。如果是首字符串是"STAY"则表示Cobb在该层梦境 中停留了一段时间,本行随后将是一个整数S表示在该层停留了S分钟(1<=S<=10000000)。数据保证在现实世界中,时间过了整数 秒。
    输出
    对于每组测试数据,输出现实世界过的时间(以秒为单位)。
    样例输入
    1
    6
    IN
    STAY 60
    IN
    STAY 1440
    OUT
    OUT
    样例输出
    396
    来源
    通信兴趣小组选拨赛
    上传者
    admin
     
    #include <iostream>
    #include <string>
    using namespace std;
    int main() {
    	int n, m;
    	cin >> n;
    	while (n--) {
    		double jt = 0, min, tt = 1;
    		cin >> m;
    		while (m--) {
    			string s;
    			cin >> s;
    			if (s == "IN") {
    				tt *= 20;
    				continue;
    			}
    			if (s == "OUT") {
    				tt /= 20;
    				continue;
    			}
    			cin >> min;
    			jt += min / tt;
    		}
    		cout << jt * 60 << endl;
    	}
    	return 0;
    }
      
    #include<iostream>//最优程序
    #include<string>
    using namespace std;
    int main()
    {
        int m;
        string s;
        cin>>m;
        while(m--)
        {
            int p=1,n,t=0,tt;
            cin>>n;
            while(n--)
            {
                cin>>s;
                if(s=="STAY")
                {
                    cin>>tt;
                    t+=tt*60/p;
                }
                else if(s=="IN") p*=20;
                else p/=20;
            }
            cout<<t<<endl;
        }
    }        
           

    168、

    房间安排

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述

    2010 年上海世界博览会(Expo2010),是第41届世界博览会。于2010年5月1日至10月31日期间,在中国上海市举行。本次世博会也是由中国举办的 首届世界博览会。上海世博会以“城市,让生活更美好”(Better City,Better Life)为主题,将充分探索21世纪城市生活。

    这次世博会总投资达450亿人民币,创造了世界博览会史上的最大规模记录。吸引200个国家和国际组织参展。预计有7000万人次的参观者。

    为 了更好地接待在这期间来自世界各地的参观者,如何合理安排各宾馆的住房问题提到了日程。组委会已接到了大量的客户住宿定单,每张定单的内容包括要住宿的房 间数,开始住宿时间和要住的天数。为了便于整个城市各宾馆的管理,组委会希望对这些定单进行安排,目的是用尽可能少的房间来满足这些定单,以便空出更多的 房间用于安排流动游客。

    组委会请求DR.Kong来完成这个任务,对这些定单进行合理安排,使得满足这些定单要求的房间数最少。

    假设:某个定单上的游客一旦被安排到某房间,在他预定住宿的期间内是不换房间的。为了简化描述,定单上的开始住宿时间为距离现在的第几天。例如,定单为(10,30,5)表示游客要求使用10个房间,第30天开始连住5天。

    输入
    第一行:T 表示有T组测试数据
    每组测试数据第一行:N 表示定单数
    每组测试数据接下来有N行,每行有三个整数 A B C 表示房间数,开始住宿时间和天数
    1<=T<=100
    1<=N<=10000 1<=A<=10 1<=B<=180 1<=c<=10
    输出
    输出一个整数,为满足所有定单要求的最少房间数。
    样例输入
    1
    3
    3 10 4
    4 9 3
    3 12 6
    样例输出
    7
    来源
    第三届河南省程序设计大赛
    上传者
    张云聪
     
    #include <iostream>
    using namespace std;
    
    int main() {
    	int n;
    	cin>>n;
    	while(n--){
    		int m,a[200]={0},b,c,d;//计算出每天的最大人数,即房间数,保存
    		cin>>m;
    		while(m--){
    			cin>>b>>c>>d;
    			for(int i=c;i<c+d;i++)//是<,第c+d天不住的
    				a[i]+=b;
    		}
    		int max=a[1];
    		for(int i=2;i<181;i++)
    			if(a[i]>max)
    				max=a[i];
    		cout<<max<<endl;
    	}
    	return 0;
    }  
     
    #include <stdio.h>//最优程序
    #include <string.h>
    #define MAX 200
    int Scan(){
        int res=0 , ch;
        while(!((ch=getchar()) >= '0' && ch <= '9'))
            if(ch==EOF) return EOF;
            res=ch-'0';
            while((ch=getchar()) >= '0' && ch <= '9')
                res = res*10 + (ch-'0');
            return res;
    }
    int main()
    {
        int Ncase,d[MAX];
        scanf("%d",&Ncase);
        while(Ncase--){
            memset(d,0,sizeof(d));
            int max = -1, n, a, b, c;
            n = Scan();
            while(n--){
                a = Scan();    b = Scan();    c = Scan();
                d[b] += a;
                d[b+c] -= a;
            }
            for (int i = 1 ; i < MAX ; i++){
                d[i] = d[i-1] + d[i];
                if (max < d[i]){
                    max = d[i];
                }
            }
            printf("%d
    ",max);
        }
        return 0;
    }        
          

    169、

    素数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    走进世博园某信息通信馆,参观者将获得前所未有的尖端互动体验,一场充满创想和喜悦的信息通信互动体验秀将以全新形式呈现,从观众踏入展馆的第一步起,就将与手持终端密不可分,人类未来梦想的惊喜从参观者的掌上展开。

    在 等候区的梦想花园中,参观者便开始了他们奇妙的体验之旅,等待中的游客可利用手机等终端参与互动小游戏,与梦想剧场内的虚拟人物Kr. Kong 进行猜数比赛。当屏幕出现一个整数X时,若你能比Kr. Kong更快的发出最接近它的素数答案,你将会获得一个意想不到的礼物。

    例如:当屏幕出现22时,你的回答应是23;当屏幕出现8时,你的回答应是7;若X本身是素数,则回答X;若最接近X的素数有两个时,则回答大于它的素数。

    输入
    第一行:N 要竞猜的整数个数
    接下来有N行,每行有一个正整数X
    1<=N<=5 1<=X<=1000
    输出
    输出有N行,每行是对应X的最接近它的素数
    样例输入
    4
    22
    5
    18
    8
    样例输出
    23
    5
    19
    7
    来源
    第三届河南省程序设计大赛
    上传者
    张云聪
     
    #include<stdio.h>
    int main()
    {
        int a[1010]= {1,1};
        int i,j;
        for(i=2; i<32; i++)
        {
            if(a[i]==0)
                for(j=i*i; j<1010; j+=i)
                    a[j]=1;
        }
        int N;
        scanf("%d",&N);
        while(N--)
        {
            int n;
            scanf("%d",&n);
            for(i=n; a[i]==1; i--);
            for(j=n; a[j]==1; j++);
            if((j-n)<=(n-i))
                printf("%d
    ",j);
            else
                printf("%d
    ",i);
        }
    } 
     
     
    #include<iostream>//最优程序
    #include<algorithm>
    using namespace std;
    int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,
    191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,
    419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,
    653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,
    919,929,937,941,947,953,967,971,977,983,991,997,1009};
        int main()
    {
        int n,m;
        cin>>n;
        while(n--)
        {
            cin>>m;
            if(m==1) {cout<<2<<endl;continue;}
            int* l=lower_bound(prime,prime+169,m);
            if(*l-m<=m-*(l-1)) cout<<*l<<endl;
            else cout<<*(l-1)<<endl;
        }
    }                
           

    198、

    数数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:2
    描述

    我们平时数数都是喜欢从左向右数的,但是我们的小白同学最近听说德国人数数和我们有些不同,他们正好和我们相反,是从右向左数的。因此当他看到123时会说“321”。

    现在有一位德国来的教授在郑州大学进行关于ACM的讲座。现在他聘请你来担任他的助理,他给你一些资料让你找到这些资料在书中的页数。现在你已经找到了对应的页码,要用英文把页码告诉他。

    为了简化我们的问题,你只需要返回单词的大写的首字母。(数字0读成字母O)

    注意:每个数字式单独读取的,因此不会出现11读成double one的情况。

    输入
    输入分两部分:
    第一部分:一个整数T(1<=T<=1000)
    第二部分:一共T行,每行为一个数字。每个数的长度不超过10位。
    输出
    每组输出单独占一行,输出对应的返回给德国教授的页码缩写。
    样例输入
    2
    12
    1234
    
    样例输出
    TO
    FTTO
    来源
    郑州大学校赛题目
    上传者
    张云聪
     
    #include<iostream>
    #include<string>
    using namespace std;
    int main ( )
    {
    	int n;
    	cin >> n;
    	while ( n-- )
    	{
    		string s;
    		cin>>s;
    		for ( int i = s.size()-1; i >=0; i-- )
    		{
    			switch ( s[i] )
    			{
    					case '0':
    					case '1':
    						cout << "O"; break;
    					case '2':
    					case '3':
    						cout << "T"; break;
    					case '4':
    					case '5':
    						cout << "F"; break;
    					case '6':
    					case '7':
    						cout << "S"; break;
    					case '8':
    						cout << "E"; break;
    					case '9':
    						cout << "N"; break;
    			}
    		}
    		cout << endl;
    	}
    	//system ( "PAUSE" );
    	return 0;
    }   
     
    #include<cstdio>//最优程序
    char str[]="OOTTFFSSENT";
    void show(int t)
    {
        if(t){putchar(*(str+t%10));show(t/10);}
    }
    int main()
    {
        int n,t;
            scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            show(n);puts("");
        }
    }                 

    199、

    无线网络覆盖

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:3
    描述

    我们的乐乐同学对于网络可算得上是情有独钟,他有一个计划,那就是用无线网覆盖郑州大学。

    现 在学校给了他一个机会,因此他要购买很多的无线路由。现在他正在部署某条大道的网络,而学校只允许把他的无线路由器放在路的正中间。我们默认这条大道是笔 直的并且它在任何地方的宽度都一样。并且所有的路由器的覆盖面积是相同的。现在乐乐计算出这条大道的长和宽,以及路由器的覆盖半径,想请你帮忙,帮他计算 出他最少要购买的路由器的数量。

    注意:为了防止某种干扰,两台无线路由之间的最小距离不能小于1米

    图1中为一条矩形的道路,中间的虚线代表中线。图2为最小覆盖的示意图。

    输入
    输入包括多组测试数据
    第一部分:一个整数T(1<=T<=500)
    第二部分:一共T行,每行包括三个整数L,D,R代表路的长,宽和覆盖半径(米)。
    (1<=L<=100000),(1<=D<=50),(1<=R<=200)。
    输出
    对于每组测试数据输出各占一行,只有一个整数,表示最少的路由器数量。如果不能覆盖,请输出impossible
    样例输入
    2
    40 6 5
    40 10 5
    样例输出
    5
    impossible
    来源
    郑州大学校赛题目
    上传者
    张云聪
     
    /*
     * http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=199
     * by jtahstu on 2015/2/11 16:00
     */
    #include <iostream>
    #include <cmath>
    using namespace std;
    int main() {
    	int r, d, l, n;
    	cin >> n;
    	while (n--) {
    		cin >> l >> d >> r;
    		if (4 * r * r - d * d < 1) {
    			cout << "impossible" << endl;
    		} else {
    			double a = sqrt((2 * r) * (2 * r) * 1.0 - (d * d));
    			if ((int) (l / a) == l / a)
    				cout << (int) (l / a) << endl;
    			else
    				cout << (int) (l / a) + 1 << endl;
    		}
    	}
    	return 0;
    } 
     
    #include<stdio.h>//最优程序
    #include<math.h>
    int main(){int T;double L,D,R,a;
    scanf("%d",&T);while(T--)
    {scanf("%lf%lf%lf",&L,&D,&R);
    a=4*R*R-D*D;if(a>0)printf("%.0lf
    ",ceil(L/sqrt(a)));
    else puts("impossible");}}        
           

    204、

    Coin Test

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    As is known to all,if you throw a coin up and let it droped on the desk there are usually three results. Yes,just believe what I say ~it can be the right side or the other side or standing on the desk, If you don't believe this,just try In the past there were some famous mathematicians working on this .They repeat the throwing job once again. But jacmy is a lazy boy.He is busy with dating or playing games.He have no time to throw a single coin for 100000 times. Here comes his idea,He just go bank and exchange thousands of dollars into coins and then throw then on the desk only once. The only job left for him is to count the number of coins with three conditions.

    He will show you the coins on the desk to you one by one. Please tell him the possiblility of the coin on the right side as a fractional number if the possiblity between the result and 0.5 is no larger than 0.003. BE CAREFUL that even 1/2,50/100,33/66 are equal only 1/2 is accepted ! if the difference between the result and 0.5 is larger than 0.003,Please tell him "Fail".Or if you see one coin standing on the desk,just say "Bingo" any way.

    输入
    Three will be two line as input.
    The first line is a number N(1<N<65536)
    telling you the number of coins on the desk.
    The second line is the result with N litters.The letter are "U","D",or "S","U" means the coin is on the right side. "D" means the coin is on the other side ."S" means standing on the desk.
    输出
    If test successeded,just output the possibility of the coin on the right side.If the test failed please output "Fail",If there is one or more"S",please output "Bingo"
    样例输入
    6
    UUUDDD
    样例输出
    1/2
    
    来源
    郑州大学校赛题目
    上传者
    张云聪
     
    #include<stdio.h>
    int divisor( int n, int m )
    {
        if( n % m == 0 )
            return m;
        else
            divisor( m, n % m );
    }
    int main( )
    {
        int n, n1 = 0, n2 = 0, m1, m2;
        char ch[65537];
        bool stand = false;
        scanf("%d", &n );
        scanf("%s", ch );
        for( int i = 0 ; i < n ; i++ )
        {
            if( ch[i] == 'U' )
                n1++;
            else if( ch[i] == 'D' )
                n2++;
            else if( ch[i] == 'S' )
                stand = true;
        }
        if( stand )
            printf("Bingo
    ");
        else if( (1.0*n1/n) > (0.5+0.003) || (1.0*n1/n) < (0.5-0.003) )
            printf("Fail
    ");
        else
            printf("%d/%d
    ", n1/divisor( n, n1 ), n/divisor( n, n1 ) );
        return 0;
    }
          
    #include<cstdio>//最优程序
    int u,d;
    int gcd(int a,int b)
    {
        if(a==0) return b;
        else return gcd(b%a,a);
    }
    int main()
    {
        int n;
        char c;
        scanf("%d",&n);
        getchar();
        for(int i=0;i!=n;i++)
        {
            c=getchar();
            if(c=='S') {puts("Bingo");return 0;}
            if(c == 'U') ++u;
            else ++d;
        }
        int g=gcd(u,u+d);
        if((double)u/(u+d)-0.5>0.003 ||(double)u/(u+d)-0.5<-0.003) puts("Fail");
        else printf("%d/%d",u/g,(u+d)/g);
    }        
       

    206、

    矩形的个数

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    在一个3*2的矩形中,可以找到6个1*1的矩形,4个2*1的矩形3个1*2的矩形,2个2*2的矩形,2个3*1的矩形和1个3*2的矩形,总共18个矩形。

    给出A,B,计算可以从中找到多少个矩形。
    输入
    本题有多组输入数据(<10000),你必须处理到EOF为止

    输入2个整数A,B(1<=A,B<=1000)

    输出
    输出找到的矩形数。
    样例输入
    1 2
    3 2
    
    样例输出
    3
    18
    
    
    来源
    FOJ月赛-2007年3月
    上传者
    ACM_赵铭浩
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
    	int a,b;
    	while(scanf("%d%d",&a,&b)!=EOF)
    	{
    		printf("%.0lf
    ",(double)a*(a+1)*b*(b+1)/4);
    	}
    	return 0;
    }   
     
    #include <stdio.h>//最优程序
    main(){float a,b;while(scanf("%f%f",&a,&b)+1)printf("%.0f
    ",(a+1)*a*(b+1)*b/4);}        
         

    216、

    A problem is easy

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:3
    描述
    When Teddy was a child , he was always thinking about some simple math problems ,such as “What it’s 1 cup of water plus 1 pile of dough ..” , “100 yuan buy 100 pig” .etc..

    One day Teddy met a old man in his dream , in that dream the man whose name was“RuLai” gave Teddy a problem :

    Given an N , can you calculate how many ways to write N as i * j + i + j (0 < i <= j) ?

    Teddy found the answer when N was less than 10…but if N get bigger , he found it was too difficult for him to solve.
    Well , you clever ACMers ,could you help little Teddy to solve this problem and let him have a good dream ?
    输入
    The first line contain a T(T <= 2000) . followed by T lines ,each line contain an integer N (0<=N <= 10^11).
    输出
    For each case, output the number of ways in one line
    样例输入
    2
    1
    3
    样例输出
    0
    1
    上传者
    苗栋栋
     
    #include<iostream>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        while(n--)
        {
            int a,count=0;
            cin>>a;
            for(int i=1; (i+1)*(i+1)<=(a+1); i++)
    
                if((a+1)%(i+1)==0)
                    count++;
    
            cout<<count<<endl;
        }
        return 0;
    }
     
    #include<cstring>
    #include<cstdio>
    #include<map>
    #include<string>
    #include<algorithm>
    #include<vector>
    #include<iostream>
    #include<cmath>
    using namespace std;
    #define CLR(arr,val) memset(arr,val,sizeof(arr))
    
    int main()
    {
        int t,n,cnt=0;
        //long long num;
        int num;
        scanf("%d",&t);
        while(t--)
        {
        //    scanf("%lld",&num);
            scanf("%d",&num);
            int nn=(int)(sqrt(num+1.0)+0.5);
            num++;
            cnt=0;
            for(int i=2;i<=nn;i++)
                if(num%i==0) cnt++;
            printf("%d
    ",cnt);
        }
        
    }    

    217、

    a letter and a number

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;
    Give you a letter x and a number y , you should output the result of y+f(x).
    输入
    On the first line, contains a number T(0<T<=10000).then T lines follow, each line is a case.each case contains a letter x and a number y(0<=y<1000).
    输出
    for each case, you should the result of y+f(x) on a line
    样例输入
    6
    R 1
    P 2
    G 3
    r 1
    p 2
    g 3
    样例输出
    19
    18
    10
    -17
    -14
    -4
    上传者
    苗栋栋
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
    	int n;
    	//freopen("input.txt","r",stdin);
    	scanf("%d",&n);
    	while(n--)
    	{
    		char a;
    		int b,c,d;
    		char ch=getchar();
    		scanf("%c%d",&a,&b);
    		c=a;
    		if(a>='A'&&a<='Z')
    		d=c-64;
    		if(a>='a'&&a<='z')
    		d=96-c;
    		printf("%d
    ",b+d);
    	}
    	return 0;
    }     
     
    #include<stdio.h>//最优程序
    main()
    {
        int x,n;
        scanf("%d",&x);
        while(x--)
        {
            getchar();
            char c;
            scanf("%c %d",&c,&n);
            if(c>=65&&c<=90) c=c-64;
            else c=0-(c-96);
            n=c+n;
            printf("%d
    ",n);
            
    
        }
    }           

    241、

    字母统计

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    现在给你一个由小写字母组成字符串,要你找出字符串中出现次数最多的字母,如果出现次数最多字母有多个那么输出最小的那个。
    输入
    第一行输入一个正整数T(0<T<25)
    随后T行输入一个字符串s,s长度小于1010。
    输出
    每组数据输出占一行,输出出现次数最多的字符;
    样例输入
    3
    abcd
    bbaa
    jsdhfjkshdfjksahdfjkhsajkf
    样例输出
    a
    a
    j
    
    来源
    [路过这]原创
    上传者
    路过这
     
    #include <stdio.h>
    #include "string.h"
    #include <iostream>
    using namespace std;
    int main(int argc, char const *argv[])
    {
        int n,i,len;
        char a[1011];
        cin>>n;
        getchar();
        while(n--)
        {
            char b[1011]={0};
            int fla=0,max=0;
            cin>>a;
            len=strlen(a);
            for(i=0; i<len; i++)
            {
    
                b[a[i]-'a']++;
            }
            max=b[0];
            for(i=0; i<26; i++)
            {
                if(b[i]>max)//||(b[i]==max&&a[i]-'a'<a[fla]-'a')
                {
                    max=b[i];
                    fla=i;
                }
            }
            cout<<(char)(fla+'a')<<endl;
        }
        return 0;
    }
       
    #include<stdio.h>//最优程序
    #include<string.h>
    main()
    {
        int x,i,max,q;
        char a[1011];
        scanf("%d",&x);
        getchar();
        while(x--)
        {
            int s[26]={0};
            gets(a);
            for(i=strlen(a)-1;i>=0;i--)
                s[a[i]-97]++;
            max=0;
            for(i=0;i<26;i++)
                if(max<s[i]) max=s[i],q=i;
            printf("%c
    ",q+97);
        }
        
    }              

    242、

    计算球体积

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    根据输入的半径值,计算球的体积。
    输入
    输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。(0<R<100)
    输出
    输出对应的球的体积,对于每组输入数据,输出一行,计算结果四舍五入为整数
    Hint:PI=3.1415926
    样例输入
    1
    1.5
    样例输出
    4
    14
    来源
    Trinity
    上传者
    张洁烽
     
    #include<stdio.h>
    int main()
    {
        double n,pi=3.1415926;
        while(scanf("%lf",&n)==1)
        {
            printf("%.0lf
    ",4*pi*n*n*n/3);
        }
        return 0;
    }
            

    243、

    交换输出

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    输入n(n<100)个数,找出其中最小的数,将它与最前面的数交换后输出这些数。(如果这个第一个数就是最小的数,则保持原样输出,如果最小的数有相同的按照前面的交换)
    输入
    输入数据有多组,每组占一行,每行的开始是一个整数n,表示这个测试实例的数值的个数,跟着就是n个整数。n=0表示输入的结束,不做处理。
    输出
    对于每组输入数据,输出交换后的数列,每组输出占一行。
    样例输入
    4 2 1 3 4
    5 5 4 3 2 1
    0
    样例输出
    1 2 3 4
    1 4 3 2 5
    来源
    [张洁烽]原创
    上传者
    张洁烽
    #include<stdio.h>
    #include<iostream>
    using namespace std;
    int main() {
    	int n, i, a[100], t, j;
    	while (cin >> n && n) {
    		j = 0;
    		for (i = 0; i < n; i++)
    			cin >> a[i];
    		t = a[0];
    		for (i = 0; i < n; i++) {
    			if (a[0] > a[i]) {
    				a[0] = a[i];
    				j = i;
    			}
    		}
    		a[j] = t;
    		for (i = 0; i < n; i++)
    			printf("%d ", a[i]);
    		printf("
    ");
    	}
    	return 0;
    }
     
     
    #include<iostream>//最优程序
    #include<iterator>
    #include<algorithm>
    using namespace std;
    int data[110];
    int main()
    {
    int n;
        while(cin>>n && n)
        {
            for(int i=0;i!=n;i++) cin>>data[i];
            iter_swap(data,min_element(data,data+n));
            copy(data,data+n,ostream_iterator<int>(cout," "));
            cout<<endl;
        }
    }                        

    244、

    16进制的简单运算

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    现在给你一个16进制的加减法的表达式,要求用8进制输出表达式的结果。
    输入
    第一行输入一个正整数T(0<T<100000)
    接下来有T行,每行输入一个字符串s(长度小于15)字符串中有两个数和一个加号或者一个减号,且表达式合法并且所有运算的数都小于31位
    输出
    每个表达式输出占一行,输出表达式8进制的结果。
    样例输入
    3
    29+4823
    18be+6784
    4ae1-3d6c
    样例输出
    44114
    100102
    6565
    来源
    [路过这]原创
    上传者
    路过这
    #include"stdio.h"
    int main() {
    	int n, a, b;
    	while (scanf("%d", &n) != EOF) {
    		while (n--) {
    			scanf("%x %x", &a, &b);
    			printf("%o
    ", a + b);
    		}
    	}
    	return 0;
    }
     
    #include<stdio.h>//最优程序
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int a,b,d;
            char c;
            scanf("%x%c%x",&a,&c,&b);
            if(c=='+') d=a+b;
            else d=a-b;
            if(d>=0)
                printf("%o
    ",d);
            else printf("-%o
    ",-d);
        }
    }       

    255、

    C小加 之 随机数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    ACM 队的“C小加”同学想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数 (0<N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排 好的顺序去找同学做调查。请你协助 C小加 完成“去重”与“排序”的工作。
    输入
    第一行输入整数T(1<T<10)表示多少组测试数据,
    每组测试数据包括2行,
    第1行为1个正整数,表示所生成的随机数的个数:N(0<N≤100)
    第2行有N个用空格隔开的正整数,为所产生的随机数。
    (随机数为题目给定的,不需要ACMer生成)
    输出
    输出也是2行,第1行为1个正整数M,表示不相同的随机数的个数。
    第2行为M个用空格隔开的正整数,为从小到大排好序的不相同的随机数。
    样例输入
    1
    10
    20 40 32 67 40 20 89 300 400 15
    样例输出
    8
    15 20 32 40 67 89 300 400
    来源
    RQNOJ
    上传者
    唐博
     
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main(int argc, char const *argv[])
    {
        int n;
        cin>>n;
        while(n--)
        {
            int m,i,a[110],count;
            count=0;
            cin>>m;
            for(i=0; i<m; i++)
                cin>>a[i];
            sort(a,a+m);
            for(i=0; i<m; i++)
            {
                if(a[i]!=a[i+1]) count++;
                else if(a[i]==a[i+1]) a[i]=-1;
            }
            cout<<count<<endl;
            for(i=0; i<m; i++)
            {
                if(a[i]!=-1) cout<<a[i]<<" ";
            }
            cout<<endl;
        }
        return 0;
    }
      
    #include<iostream>//最优程序
    #include<map>
    #include<cstdio>
    #include<algorithm>
    #include<iterator>
    using namespace std;
    const int maxn=110;
    int tab[maxn];
    int main()
    {
         
        int t;cin>>t;
        while(t--){
            int n;cin>>n;
            for(int i=0;i<n;i++)scanf("%d",&tab[i]);
            sort(tab,tab+n);
            cout<<(n=distance(tab,unique(tab,tab+n)))<<endl;
            copy(tab,tab+n,ostream_iterator<int>(cout," "));cout<<endl;
        }
        
    }              

    259、

    茵茵的第一课

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:0
    描述

    茵茵今年已经六年级了,爸爸给她报了一个学习程序设计的班。

    第一节课上,老师讲的就是如何输入一个数,再原样输出出来。

    以现在的你看来,挺容易的是不?
    那么,就请你也写出一个一样的程序吧

    输入
    第一行是一个整数N(N<10)表示测试数据的组数)
    接下来的n行 每行只有一个数(可能是小数,也可能是整数)
    这个数的位数(整数位数+小数位数)不超过19位
    输出
    原样输出每个数,每输出占一行
    样例输入
    2
    3.5
    5
    样例输出
    3.5
    5
    来源
    2008年小学生程序设计友谊赛试题
    上传者
    ACM_赵铭浩
     
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	int n;
    	char a[20];
    	scanf("%d",&n);
    	while(n--)
    	{
    		scanf("%s",a);
    		printf("%s
    ",a);
    	}
    	return 0;
    }        

    260、

    数数小木块

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    在墙角堆放着一堆完全相同的正方体小木块,如下图所示:

     

     因为木块堆得实在是太有规律了,你只要知道它的层数就可以计算所有木块的数量了。

    现在请你写个程序 给你任一堆木块的层数,求出这堆木块的数量.

    输入
    第一行是一个整数N(N<=10)表示测试数据的组数)
    接下来的n行 每行只有一个整数 ,表示这堆小木块的层数,
    输出
    对应每个输入的层数有一个输出,表示这堆小木块的总数量,每个输出占一行
    样例输入
    215
    样例输出
    135
    来源
    2008年小学生程序设计友谊赛试题
    上传者
    ACM_赵铭浩
     
    #include "iostream"
    using namespace std;
    int main()
    {
        int n,i,a,b[10001],sum;
        cin>>n;
         b[0]=0;
         for(i=1;i<=10001;i++)
            {b[i]=b[i-1]+i;}
        while(n--)
        {
            sum=0;
            cin>>a;
                for(i=1;i<=a;i++)
                  {sum+=b[i];}
            cout<<sum<<endl;
        }
        return 0;
    }  
     
    #include <stdio.h>//最优程序
    int main()
    {
        int n,t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            printf("%d
    ",n*(n+1)*(n+2)/6);
        }
    }        
          

    263、

    精 挑 细 选

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    小王是公司的仓库管理员,一天,他接到了这样一个任务:从仓库中找出一根钢管。这听起来不算什么,但是这根钢管的要求可真是让他犯难了,要求如下:
    1、 这根钢管一定要是仓库中最长的;
    2、 这根钢管一定要是最长的钢管中最细的;
    3、 这根钢管一定要是符合前两条的钢管中编码最大的(每根钢管都有一个互不相同的编码,越大表示生产日期越近)。
    相关的资料到是有,可是,手工从几百份钢管材料中选出符合要求的那根……
    要不,还是请你编写个程序来帮他解决这个问题吧。
    输入
    第一行是一个整数N(N<=10)表示测试数据的组数)
    每组测试数据的第一行 有一个整数m(m<=1000),表示仓库中所有钢管的数量,
    之后m行,每行三个整数,分别表示一根钢管的长度(以毫米为单位)、直径(以毫米为单位)和编码(一个9位整数)。
    输出
    对应每组测试数据的输出只有一个9位整数,表示选出的那根钢管的编码,
    每个输出占一行
    样例输入
    222000 30 1234567892000 20 98765432143000 50 8721984423000 45 7524981242000 60 7651287423000 45 652278122
    样例输出
    987654321752498124
    来源
    2008年小学生程序设计友谊赛试题
    上传者
    ACM_赵铭浩
     
    #include<stdio.h>
    int main()
    {
        int n;
        scanf("%d",&n);
        while(n--)
        {
            int m,a,b,c,a1,b1,c1;
            scanf("%d",&m);
            scanf("%d%d%d",&a,&b,&c);
            for(int i=1; i<m; i++)
            {
                scanf("%d%d%d",&a1,&b1,&c1);
                if(a1>a||(a1==a&&b1<b)||(a1==a&&b1==b&&c1>c))
                    a=a1,b=b1,c=c1;
            }
            printf("%d
    ",c);
        }
        return 0;
    }      
     
    #include<stdio.h>//最优程序
    int main()
    {
        int n,m,i,a,b,c,x,y,z;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&m);
            a=0;b=0;c=0;
            for(i=0;i<m;i++)
            {
                scanf("%d%d%d",&x,&y,&z);
                if(x>a||x==a&&y<b||x==a&&y==b&&z>c) { a=x;b=y;c=z; }
            }
            printf("%d
    ",c);
        }
        return 0;
    }        
      

    264、

    国王的魔镜

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    国王有一个魔镜,可以把任何接触镜面的东西变成原来的两倍——只是,因为是镜子嘛,增加的那部分是反的。

    比如一条项链,我们用AB来表示,不同的字母表示不同颜色的珍珠。如果把B端接触镜面的话,魔镜会把这条项链变为ABBA。如果再用一端接触的话,则会变成ABBAABBA(假定国王只用项链的某一端接触魔镜)。

    给定最终的项链,请编写程序输出国王没使用魔镜之前,最初的项链可能的最小长度。

    输入
    第一行是一个整数N(N<=10)表示测试数据的组数)
    每组测试数据占一行 只有一个字符串(长度小于100),由大写英文字母组成,表示最终的项链。
    输出
    每组测试数据的输出只有一个整数,表示国王没使用魔镜前,最初的项链可能的最小长度。
    样例输入
    2ABBAABBAA
    样例输出
    21
    来源
    2008年小学生程序设计友谊赛试题
    上传者
    ACM_赵铭浩
     
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int main()
    {
        int temp,k,i;
        char s[100];
        scanf("%d",&temp);
        getchar();
        while(temp--)
        {
            gets(s);
            k=strlen(s);
            while(k)
            {
                for(i=0; i<k; ++i)
                    if(s[i]!=s[k-1-i]||k==1||k%2)
                    {
                        cout<<k<<endl;
                        k=0;
                    }
                k=k/2;
            }
        }
    }
       
    #include<stdio.h>//最优程序
    #include<string.h>
    main()
    {
        int z,x,q,i;
        char a[101],t[51];
        scanf("%d",&z);
        getchar();
        while(z--)
        {
            gets(a);
            do
            {
                x=strlen(a);
                if(x%2) break;
                for(i=0;i<x/2;i++)
                    t[i]=a[x-1-i];
                t[i]='';
                a[x/2]='';
                q=strcmp(a,t);
            }while(q==0);
            printf("%d
    ",x);
        }
    }        
          

    266、

    字符串逆序输出

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:0
    描述
    给定一行字符,逆序输出此行(空格.数字不输出)
    输入
    第一行是一个整数N(N<10)表示测试数据的组数)
    每组测试数据占一行,每行数据中间有且只有一个空格(这样你可以把此行当成两个字符串读取)。
    每行字符长度不超过40
    并且保证输入的字符只有空格(1个),数字,小写字母三种
    输出
    对应每行测试数据,逆序输出(空格和数字不输出)
    样例输入
    3
    abc 123de
    abc 123
    abc d
    样例输出
    edcba
    cba
    dcba
    来源
    [521521]原创
    上传者
    ACM_赵铭浩
     
    #include <stdio.h>
    #include <string.h>
    int main(void)
    {
        int n,k,i;
        char a[100];
        //freopen("input.txt", "r", stdin);
        scanf("%d",&n);
        getchar();
        while(n--)
        {
            gets(a);
            k=strlen(a);
            for(i=k-1; i>=0; i--)
                if(a[i]>='a'&&a[i]<='z')
                    printf("%c",a[i]);
            printf("
    ");
        }
        return 0;
    }
         
    #include <stdio.h>
    void revers()
    {
        char c;
        if((c = getchar()) != '
    ')
            revers();
        if(c != '
    '&&c>='a'&&c<='z')
            putchar(c);
    }
    
    int main()
    {
        int a;
        scanf("%d
    ",&a);
        while(a--)
        {
            revers();
            printf("
    ");
        }
        return 0;
    }            

    268、

    荷兰国旗问题

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
     
    荷兰国旗有三横条块构成,自上到下的三条块颜色依次为红、白、蓝。现有若干由红、白、蓝三种颜色的条块序列,要将它们重新排列使所有相同颜色的条块在一起。本问题要求将所有红色的条块放最左边、所有白色的条块放中间、所有蓝色的条块放最右边。
    输入
    第1行是一个正整数n(n<100),表示有n组测试数据。接下来有n行,每行有若干个由R,W,B三种字符构成的字符串序列,其中R,W和B分别表示红、白、蓝三种颜色的条块,每行最多有1000个字符。
    输出
    对输入中每行上由R,W,B三种字符构成的字符串序列,将它们重新排列使所有相同颜色的条块在一起,满足前述要求。
    样例输入
    3BBRRWBWRRRRRRWWRWRBRBRW 
    样例输出
    RRRRRWWBBBRRRRRWWWBRRWB 
    来源
    acm教材
    上传者
    李文鑫
     
    #include "iostream"
    #include "cstdio"
    #include "cstring"
    using namespace std;
    int main(int argc, char const *argv[])
    {
    	int n,i;
    	char a[1001];
    	cin>>n;
    	getchar();
    	while(n--)
    	{
    		int x=0,y=0,z=0,m=0;
            //把getchar();放这里了,我去
    		gets(a);
    		m=strlen(a);
    		for(i=0;i<m;i++)
    		{
    			if(a[i]=='R')x++;
    			if(a[i]=='W')y++;
    			if(a[i]=='B')z++;
    		}
    		for (i=0;i<x;i++)
    		cout<<'R';
    		for(i=0;i<y;i++)
    			cout<<'W';
    		for(i=0;i<z;i++)
    			cout<<'B';
    		cout<<endl;
    	}
    	return 0;
    }
       
    #include<stdio.h>//最优程序
    int main()
    {
        int n;
        scanf("%d",&n);
        getchar();
        while(n--)
        {
            int w=0,b=0;
            char c;
            while((c=getchar())!=10)
                c=='R'?printf("R"):(c=='W'?w++:b++);
            while(w--)
                putchar('W');
            while(b--)
                putchar('B');
            printf("
    ");
        }
    }            

    273、

    字母小游戏

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述
    给你一个乱序的字符串,里面包含有小写字母(a--z)以及一些特殊符号,请你找出所给字符串里面所有的小写字母的个数, 拿这个数对26取余,输出取余后的数字在子母表中对应的小写字母(0对应z,1对应a,2对应b....25对应y)。
    输入
    第一行是一个整数n(1<n<1000)表示接下来有n行的字符串m(1<m<200)需要输入
    输出
    输出对应的小写字母 每个小写字母单独占一行
    样例输入
    2
    asdasl+%$^&ksdhkjhjksd
    adklf&(%^(alkha
    样例输出
    q
    j
    来源
    [zinber]原创
    上传者
    zinber
     
    #include "stdio.h"
    #include "string.h"
    int main(int argc, char const *argv[])
    {
        int n;
        char a;
        //freopen("input.txt","r",stdin);
        scanf("%d",&n);
        getchar();
        while(n--)
        {
           int number=0;  
           while(scanf("%c",&a),a!='
    ')
            {
                if (a>='a'&&a<='z')
                    number++;
            }
            if (number%26==0)
                printf("z
    ");
            else
                printf("%c
    ",'a'+number%26-1);
        }
        return 0;
    }  
     
    #include <cstdio>//最优程序
    #include <cctype>
    #include <cstring>
    int main(){
        int n,i;
        char arr[201];
        scanf("%d",&n);
        while(n--){
            scanf("%s",arr);
            int l=strlen(arr),r=0;
            for(int i=0;i!=l;i++)
                if(islower(arr[i]))
                    r++;
            r%=26;
            printf("%c
    ",r==0?'z':96+r);
        }
    }            

    274、

    正三角形的外接圆面积

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述
    给你正三角形的边长,pi=3.1415926 ,求正三角形的外接圆面积。
    输入
    只有一组测试数据 第一行输入一个整数n(1<n<1000)表示接下来要输入n个边长m(1.0<=m<1000.0)
    输出
    输出每个正三角形的外接圆面积,保留两位小数,每个面积单独占一行。
    样例输入
    5
    1
    13
    22
    62
    155
    样例输出
    1.05
    176.98
    506.84
    4025.43
    25158.92
    来源
    [zinber]原创
    上传者
    zinber
     
    #include<stdio.h>
    #define pi 3.1415926
    int main()
    {
        double a,s=0;
        int n;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%lf",&a);
            s=a*a*pi/3;
            printf("%.2lf
    ",s);
        }
        return 0;
    }
       
    #include<stdio.h>//最优程序
    int main()
    {
       int n;
       double m,pi=3.1415926;
       scanf("%d",&n);
       while(n--)
       {
       scanf("%lf",&m);
       printf("%.2lf
    ",pi*m*m/3);
        }
    return 0;
    }        
          

    275、

    队花的烦恼一

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    ACM队的队花C小+经常抱怨:“C语言中的格式输出中有十六、十、八进制输出,然而却没有二进制输出,哎,真遗憾!谁能帮我写一个程序实现输入一个十进制数n,输出它的二进制数呀?”

    难道你不想帮帮她吗?^_^

    输入
    输入有多个数据,数据以EOF结束;每个数据ni(0<=ni<=1000010000)用空格隔开;
    (温馨提示:EOF即是一个文件的结束标志;while(scanf("%d",&n)!=EOF){})
    输出
    输出有多行,每行对应一个十进制数ni的二进制数;
    注意:输出的二进制去掉任何一个多余的0;
    样例输入
    0 1 2 10
    样例输出
    0
    1
    10
    1010
    来源
    原创
    上传者
    Never
     
    #include "iostream"//十进制转换成二进制
    using namespace std;
    void dec_bin(const int x)
    {
        if (x/2>0)
        {
            dec_bin(x/2);
            cout<<x%2;
        }
        else cout<<x;
    }
    int main(int argc, char const *argv[])
    {
        int data=0;
        while(cin>>data)
        {
            dec_bin(data);
            cout<<endl;
        }
        return 0;
    }
            

    276、

    比较字母大小

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述

    任意给出两个英文字母,比较它们的大小,规定26个英文字母A,B,C.....Z依次从大到小。

    输入
    第一行输入T,表示有T组数据;
    接下来有T行,每行有两个字母,以空格隔开;
    输出
    输出各组数据的比较结果,输出格式见样例输出;
    (注意输出严格按照输入的顺序即输入是A B,输出时必须是A?B)
    样例输入
    3
    A B
    D D
    Z C
    样例输出
    A>B
    D=D
    Z<C
    来源
    原创
    上传者
    Never
    #include<stdio.h>
    int main() {
    	int i;
    	char a, b;
    	scanf("%d", &i);
    	while (i--) {
    		getchar();
    		scanf("%c %c", &a, &b);
    		if (a > b)
    			printf("%c<%c
    ", a, b);
    		else if (a == b)
    			printf("%c=%c
    ", a, b);
    		else if (a < b)
    			printf("%c>%c
    ", a, b);
    	}
    	return 0;
    }

    277、

    车牌号

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    茵茵很喜欢研究车牌号码,从车牌号码上可以看出号码注册的早晚,据研究发现,车牌号码是按字典序发放的,现在她收集了很多车牌号码,请你设计程序帮她判断注册较早的号码。车牌号码由5个字母或数字组成
    输入
    第一行是n,代表有n组数据,第二行是m,以下m行是m个车牌号码
    其中n<100,m<1000
    输出
    输出注册较早的车牌号
    样例输入
    1
    4
    AA100
    aa100
    0o2r4
    ye2er
    样例输出
    0o2r4
    来源
    [侯飒飒]原创
    上传者
    侯飒飒
     
    #include "iostream"
    #include "string.h"
    #include "cstdio"
    using namespace std;
    int main(int argc, char const *argv[])
    {
        int n;
        cin>>n;
        while(n--)
        {
            int m,i;
            char a[6]="zzzzz",str[6];
            cin>>m;
            getchar();
            for(i=0; i<m; i++)
            {
                scanf("%s",str);
                if(strcmp(a,str)>0)
                    strcpy(a,str);
            }
            printf("%s
    ",a);
        }
        return 0;
    } 
     
    #include<stdio.h>//最优程序
    #include<string.h>
    main(){int n;scanf("%d",&n);while(n--)
    {int m;char a[6],c[6];scanf("%d",&m);getchar();gets(c);
    while(--m){gets(a);if(strcmp(a,c)<0)strcpy(c,a);}puts(c);}}        
           

    283、

    对称排序

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    In your job at Albatross Circus Management (yes, it's run by a bunch of clowns), you have just finished writing a program whose output is a list of names in nondescending order by length (so that each name is at least as long as the one preceding it). However, your boss does not like the way the output looks, and instead wants the output to appear more symmetric, with the shorter strings at the top and bottom and the longer strings in the middle. His rule is that each pair of names belongs on opposite ends of the list, and the first name in the pair is always in the top part of the list. In the first example set below, Bo and Pat are the first pair, Jean and Kevin the second pair, etc.
    输入
    The input consists of one or more sets of strings, followed by a final line containing only the value 0. Each set starts with a line containing an integer, n, which is the number of strings in the set, followed by n strings, one per line, NOT SORTED. None of the strings contain spaces. There is at least one and no more than 15 strings per set. Each string is at most 25 characters long.
    输出
    For each input set print "SET n" on a line, where n starts at 1, followed by the output set as shown in the sample output.
    If length of two strings is equal,arrange them as the original order.(HINT: StableSort recommanded)
    样例输入
    7
    Bo
    Pat
    Jean
    Kevin
    Claude
    William
    Marybeth
    6
    Jim
    Ben
    Zoe
    Joey
    Frederick
    Annabelle
    5
    John
    Bill
    Fran
    Stan
    Cece
    0
    样例输出
    SET 1
    Bo
    Jean
    Claude
    Marybeth
    William
    Kevin
    Pat
    SET 2
    Jim
    Zoe
    Frederick
    Annabelle
    Joey
    Ben
    SET 3
    John
    Fran
    Cece
    Stan
    Bill
    来源
    POJ
    上传者
    sadsad
     
    #include<string>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    bool cmp(string a, string b) {
     return a.size() < b.size();
     }
    int main()
    {
        int n;
        int count=0;
        string a[10001];
        while(cin>>n)
        {
            if(n==0)break;
    
                for(int i=0;i<n;i++)
                {
                    cin>>a[i];
                }
                sort(a,a+n,cmp);//sort
                cout<<"SET "<<++count<<endl;
            for(int i=0;i<n;i+=2)
                cout<<a[i]<<endl;
            if(n%2==0)
            {
                for(int i=n-1;i>0;i-=2)
                    cout<<a[i]<<endl;
            }
            else for(int i=n-2;i>0;i-=2)
                cout<<a[i]<<endl;
        }
    
        return 0;
    }
      
    #include<stdio.h>//最优程序
    #include<string.h>
    main()
    {
        int x,i,j,q=0;
        char s[16][26],t[26],z[16][26];
        while(1)
        {
            scanf("%d",&x);
            if(x==0) break;
            q++;
            getchar();
            for(i=0;i<x;i++)
                gets(s[i]);
            for(i=1;i<x;i++)
                for(j=0;j<x-i;j++)
                    if(strlen(s[j])>strlen(s[j+1])) 
                    {strcpy(t,s[j]);strcpy(s[j],s[j+1]);strcpy(s[j+1],t);}
            for(i=0,j=0;i<x;i++,j++)
            {    strcpy(z[j],s[i]);
                if(i!=x-1) strcpy(z[x-j-1],s[++i]);
            }
            printf("SET %d
    ",q);
            for(i=0;i<x;i++)
                puts(z[i]);
        }
    }        
           

    324、

    猴子吃桃问题

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:0
    描述
    有一堆桃子不知数目,猴子第一天吃掉一半,又多吃了一个,第二天照此方法,吃掉剩下桃子的一半又多一个,天天如此,到第m天早上,猴子发现只剩一只桃子了,问这堆桃子原来有多少个? (m<29)
    输入
    第一行有一个整数n,表示有n组测试数据(从第二行开始,每一行的数据为:第m天);
    输出
    每一行数据是桃子的总个数
    样例输入
    2
    3
    11
    样例输出
    22
    6142
    来源
    网络
    上传者
    首席执行官
     
    #include "stdio.h"
    int f(int m)
    {
    	if(m==0) return 1;
    	else return 2*(f(m-1)+1);
    }
    int main()
    {
       	int n,m;
       	//freopen("input.txt","r",stdin);
        scanf("%d",&n);
        while(n--)
        {
        	scanf("%d",&m);
        	printf("%d
    ",f(m));
        }
        return 0;
    }
      
    #include<stdio.h>//最优程序
    int main()
    {
        int n,m;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&m);
            printf("%d
    ",(3<<m)-2);
        }
        return 0;
    }        
           

    399、

    整除个数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    1、2、3… …n这n(0<n<=1000000000)个数中有多少个数可以被正整数b整除。
    输入
    输入包含多组数据
    每组数据占一行,每行给出两个正整数n、b。
    输出
    输出每组数据相应的结果。
    样例输入
    2 1
    5 3
    10 4
    
    样例输出
    2
    1
    2
    
    来源
    自编
    上传者
    mix_math
     
    #include<stdio.h>
    int main()
    {
    int n,b;
    while(scanf("%d%d",&n,&b)!=EOF)
    {
    int count;
    count=n/b;
    printf("%d
    ",count);
    }
    return 0;
    }  
     
    #include <iostream>//最优程序
    using namespace std;
    int main()
    {
        int n,r;
        while(cin>>n>>r)
        cout<<n/r<<endl;
    }        
          

    455、

    黑色帽子

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
            最近发现了一个搞笑的游戏,不过目前还没玩过。一个舞会上,每个人头上都戴着一顶帽子,帽子只有黑白两种,黑的至少有一顶。每个人都能看到别人帽子的颜 色,可是看不见自己的。主持人先让大家看看别人头上戴的是什么帽子,然后关灯,如果有人认为自己戴的的黑色帽子,就打自己一个耳光(,都很自觉,而且不许打别人的哦),开灯,关灯,开灯……。因为都不想打自己耳光,所以不确定的情况下都不会打自己的,现在有n顶黑色帽子,第几次关灯才会听到有人打自己耳光?
    输入
    第一行只有一个整数m(m<=100000),表示测试数据组数。
    接下来的m行,每行有一个整数n(n<=100000000),表示黑色帽子的顶数。
    输出
    输出第几次关灯能听到耳光声,每组输出占一行。
    样例输入
    1
    2
    
    样例输出
    2
    
    
    来源
    原创
    上传者
    ACM_杨延玺
     
    #include<stdio.h>
    int main()
    {
        int k;
        scanf("%d",&k);
        while(k--)
        {
            int n;
            scanf("%d",&n);
            printf("%d
    ",n);
        }
        return 0;
    }
      
    #include<cstdio>//最优程序
    main(){char _[15];gets(_);while(gets(_))puts(_);}        
           

    457、

    大小写互换

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述
          现在给出了一个只包含大小写字母的字符串,不含空格和换行,要求把其中的大写换成小写,小写换成大写,然后输出互换后的字符串。
    输入
    第一行只有一个整数m(m<=10),表示测试数据组数。
    接下来的m行,每行有一个字符串(长度不超过100)。
    输出
    输出互换后的字符串,每组输出占一行。
    样例输入
    2
    Acm
    ACCEPTED
    
    样例输出
    aCM
    accepted
    
    来源
    原创
    上传者
    ACM_杨延玺
    #include<stdio.h>
    #include<string.h>
    int main() {
    	int n, i, len;
    	char a[100];
    	scanf("%d", &n);
    	while (n--) {
    		scanf("%s", a);
    		len = strlen(a);
    		for (i = 0; i < len; i++) {
    			if (a[i] <= 'z' && a[i] >= 'a')
    				a[i] = a[i] - 32;
    			else
    				a[i] = a[i] + 32;
    		}
    		printf("%s
    ", a);
    	}
    	return 0;
    }
     
    #include<stdio.h>//最优程序
    int main()
    {
        int a,b,c,n;
        char x;
        scanf("%d",&n);
        getchar();
        while(n--)
        {
            while(scanf("%c",&x)&&x!='
    ')
            {
                if(x>=97&&x<=122) printf("%c",x-32);
                else if(x<=90&&x>=64) printf("%c",x+32);
            }
            printf("
    ");
        }
    }        
    
    

    458、

    小光棍数

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    最近Topcoder的XD遇到了一个难题,倘若一个数的三次方的后三位是111,他把这样的数称为小光棍数。他已经知道了第一个小光棍数是471,471的三次方是104487111,现在他想知道第m(m<=10000000000)个小光棍数是多少?
    输入
    有多组测试数据。第一行一个整数n,表示有n组测试数据。接下来的每行有一个整数m。
    输出
    输出第m个小光棍数。
    样例输入
    1
    1
    样例输出
    471
    来源
    原创
    上传者
    wmnwmn
     
    #include "iostream"
    using namespace std;
    int main(int argc, char const *argv[])
    {
    	int n;
    	cin>>n;
    	while(n--)
    	{
            long long m;
    		cin>>m;
    		cout<<(m-1)*1000+471<<endl;
    	}
    	return 0;
    }    
     
    #include<stdio.h>//最优程序
    int main()
    {
        long long a,b,c,d,e;
        scanf("%lld",&a);
        while(a--)
        {
            scanf("%lld",&b);
            printf("%lld
    ",(b-1)*1000+471);
        }
        return 0;
    }            

    463、

    九九乘法表

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述

    小时候学过的九九乘法表也许将会扎根于我们一生的记忆,现在让我们重温那些温暖的记忆,请编程输出九九乘法表.

    是那种反过来的三角形啦,具体如下图:

    每两个式子之前用一个空格 隔开。。。

    输入
    第一有一个整数N,表示有N组数据(N<10)
    接下来由N行,每行只有一个整数M(1<=M<=9);
    输出
    对应每个整数M,根据要求输出乘法表的前N行,具体格式参见输入输出样例和上图.
    每两组测试数据结果之间有一个空行隔开,具体如输出样例。
    样例输入
    3
    2
    1
    5
    样例输出
    1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
    2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18
    
    1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
    
    1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
    2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18
    3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27
    4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36
    5*5=25 5*6=30 5*7=35 5*8=40 5*9=45
    
    来源
    原创
    上传者
    ACM_赵铭浩
     
    #include "iostream"
    using namespace std;
    int main(int argc, char const *argv[])
    {
        int n,i,j,m;
        cin>>n;
        while(n--)
        {
            cin>>m;
            for(i=1; i<=m; i++)
            {
                for(j=i; j<=9; j++)
                    cout<<i<<'*'<<j<<'='<<i*j<<' ';
                cout<<endl;
            }
        }
        return 0;
    }
       
    #include<stdio.h>//最优程序
    int main()
    {
        int t,n;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++){
                for(int j=i;j<10;j++)
                    printf("%d*%d=%d ",i,j,i*j);
                printf("
    ");
            }
        }
    }              

    477、

    A+B Problem III

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    求A+B是否与C相等。
    输入
    T组测试数据。
    每组数据中有三个实数A,B,C(-10000.0<=A,B<=10000.0,-20000.0<=C<=20000.0)
    数据保证小数点后不超过4位。

    输出
    如果相等则输出Yes
    不相等则输出No
    样例输入
    3
    -11.1 +11.1 0
    11 -11.25 -0.25
    1 2 +4
    
    样例输出
    Yes
    Yes
    No
    
    上传者
    李文鑫
     
    #include "iostream"
    using namespace std;
    int main(int argc, char const *argv[])
    {
    	int n;
    	cin>>n;
    	while(n--)
    	{
    		double a,b,c;
    		cin>>a>>b>>c;
    		if((a+b-c>-0.0001)&&(a+b-c<0.0001))
                cout<<"Yes"<<endl;
    		else cout<<"No"<<endl;
    	}
    	return 0;
    }    
     
    #include <cstdio>//最优程序
    #include <math.h>
    double a,b,c;
    main()
    {
        for(scanf("%lf",&a);~scanf("%lf%lf%lf",&a,&b,&c);puts(fabs(c-(a+b))<1e-6?"Yes":"No"));
    }        

    484、

    The Famous Clock

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述

    Mr. B, Mr. G and Mr. M are now in Warsaw, Poland, for the 2012’s ACM-ICPC World Finals Contest. They’ve decided to take a 5 hours training every day before the contest. Also, they plan to start training at 10:00 each day since the World Final Contest will do so. The scenery in Warsaw is so attractive that Mr. B would always like to take a walk outside for a while after breakfast. However, Mr. B have to go back before training starts, otherwise his teammates will be annoyed. Here is a problem: Mr. B does not have a watch. In order to know the exact time, he has bought a new watch in Warsaw, but all the numbers on that watch are represented in Roman Numerals. Mr. B cannot understand such kind of numbers. Can you translate for him?

    输入
    Each test case contains a single line indicating a Roman Numerals that to be translated. All the numbers can be found on clocks. That is, each number in the input represents an integer between 1 and 12. Roman Numerals are expressed by strings consisting of uppercase ‘I’, ‘V’ and ‘X’. See the sample input for further information.
    输出
    For each test case, display a single line containing a decimal number corresponding to the given Roman Numerals.
    样例输入
    I
    II
    III
    IV
    V
    VI
    VII
    VIII
    IX
    X
    XI
    XII
    样例输出
    Case 1: 1
    Case 2: 2
    Case 3: 3
    Case 4: 4
    Case 5: 5
    Case 6: 6
    Case 7: 7
    Case 8: 8
    Case 9: 9
    Case 10: 10
    Case 11: 11
    Case 12: 12
    来源
    HDU
    上传者
    ACM_宋志恒
     
    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
        string a;
        int count=1;
        while(cin>>a)
        {
            if(a=="I")
            {
                cout<<"Case "<<count<<": 1"<<endl;
                count++;
            }
            if(a=="II")
            {
                cout<<"Case "<<count<<": 2"<<endl;
                count++;
            }
            if(a=="III")
            {
                cout<<"Case "<<count<<": 3"<<endl;
                count++;
            }
            if(a=="IV")
            {
                cout<<"Case "<<count<<": 4"<<endl;
                count++;
            }
            if(a=="V")
            {
                cout<<"Case "<<count<<": 5"<<endl;
                count++;
            }
            if(a=="VI")
            {
                cout<<"Case "<<count<<": 6"<<endl;
                count++;
            }
            if(a=="VII")
            {
                cout<<"Case "<<count<<": 7"<<endl;
                count++;
            }
            if(a=="VIII")
            {
                cout<<"Case "<<count<<": 8"<<endl;
                count++;
            }
            if(a=="IX")
            {
                cout<<"Case "<<count<<": 9"<<endl;
                count++;
            }
            if(a=="X")
            {
                cout<<"Case "<<count<<": 10"<<endl;
                count++;
            }
            if(a=="XI")
            {
                cout<<"Case "<<count<<": 11"<<endl;
                count++;
            }
            if(a=="XII")
            {
                cout<<"Case "<<count<<": 12"<<endl;
                count++;
            }
        }
    
        return 0;
    }
      
    #include<map>//最优程序
    #include<iostream>
    #include<string>
    using namespace std;
    map<string,int>m;
    int main()
    {
        m["I"]=1;
        m["II"]=2;
        m["III"]=3;
        m["IV"]=4;
        m["V"]=5;
        m["VI"]=6;
        m["VII"]=7;
        m["VIII"]=8;
        m["IX"]=9;
        m["X"]=10;
        m["XI"]=11;
        m["XII"]=12;
        string s;
        int c=0;
        while(cin>>s)
            cout<<"Case "<<++c<<": "<<m[s]<<endl;
        return 0;
    }        
           

    596、

    谁是最好的Coder

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述
    计科班有很多Coder,帅帅想知道自己是不是综合实力最强的coder。
    帅帅喜欢帅,所以他选了帅气和编程水平作为评选标准。
    每个同学的综合得分是帅气程度得分与编程水平得分的和。
    他希望你能写一个程序帮他一下。
    输入
    数据有多组。
    输入一个数n,代表计科班的总人数。
    接下来有n行数,一行数有两个数a,b。
    其中a代表该同学的编程水平,b代表该同学的帅气程度。
    n=0表示输入结束。
    输出
    每组数据占一行,输出所有同学中综合得分最高的分数。
    样例输入
    5
    9 10
    7 11
    1 6
    5 7
    3 5
    2
    7 3
    7 6
    0
    样例输出
    19
    13
    上传者
    wsp0214
     
    #include "stdio.h"
    int main()
    {
        int n,max=0,a,b,i;
       // freopen("input.txt","r",stdin);
        while(scanf("%d",&n),n)
        {   max=0;
            for(i=0; i<n; i++)
            {
                scanf("%d%d",&a,&b);
                if((a+b)>max)max=(a+b);
            }
            printf("%d
    ",max);
        }
        return 0;
    }     
     
    #include<stdio.h>//最优程序
    main(){int n;while(scanf("%d",&n),n){int a,b,s=0;while(n--){scanf("%d%d",&a,&b);if(a+b>s) s=a+b;}printf("%d
    ",s);}}        
       

    599、

    奋斗的小蜗牛

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    传 说中能站在金字塔顶的只有两种动物,一种是鹰,一种是蜗牛。一只小蜗牛听了这个传说后,大受鼓舞,立志要爬上金字塔。为了实现自己的梦想,蜗牛找到了老 鹰,老鹰告诉它金字塔高H米,小蜗牛知道一个白天自己能向上爬10米,但由于晚上要休息,自己会下滑5米。它想知道自己在第几天能站在金字塔顶,它想让你 帮他写个程序帮助它。
    输入
    第一行有一个整数t,表示t组测试数据。
    第二行一个整数H(0<H<10^9)代表金字塔的高度。
    输出
    输出一个整数n表示小蜗牛第n天站在金字塔顶上
    样例输入
    2
    1
    5
    样例输出
    1
    1
    上传者
    ACM_王孝锋
     
    #include<stdio.h>
    int main(void)
    {
        int H,i,t;
        scanf("%d",&t);
        for(i=1; i<=t; i++)
        {
            int day=1,h=0;
            scanf("%d",&H);
            while(h+10<H)
            {
                h+=5;
                day++;
            }
            printf("%d
    ",day);
        }
        return 0;
    }
            

    733、

    万圣节派对

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述

    万圣节有一个Party,XadillaX显然也要去凑热闹了。因为去凑热闹的人数非常庞大,几十W的数量级吧,自然要进场就需要有门票了。很幸运的,XadillaX竟然拿到了一张真·门票!这真·门票的排列规则有些奇怪:

    1. 门票号是由0~6组成的六位数(0~6这几个数字可重用)

    2. 每一个门票号的每一位不能有三个连续相同的数字(如123335是不行的)

    3. 每一个门票号相邻的两位相差必须在四以下(≤4)(如016245是不行的)

    输入
    第一行一个n,代表输入个数
    接下去n行,每行两个数字x,y(x <= y)
    输出
    对于每个测试,输出x到y之间的门票编号。每个测试结尾之间空行。
    样例输入
    2
    001001 001002
    001011 001012
    样例输出
    001001
    001002
    
    001011
    001012
    来源
    NBOJ-1004
    上传者
    勿念情
     
    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int n;
        scanf("%d",&n);
        while(n--)
        {
            int ticket1, ticket2, i, j;
            int flag1, flag2, flag3;
            char x[6];
            scanf("%d %d",&ticket1, &ticket2);
            for (i = ticket1; i <= ticket2; i++)
            {
                flag1 = 1;
                flag2 = 1;
                flag3=1;
                x[0] = i / 100000 + '0';
                x[1] = i /10000 % 10 + '0';
                x[2] = i / 1000 % 10 + '0';
                x[3] = i / 100 % 10 + '0';
                x[4] = i / 10 % 10 + '0';
                x[5] = i % 10 + '0';
                for (j = 0; j < 6; j++)
                    if (x[j] - '0' > 6)
                    {
                        flag3 = 0;
                        break;
                    }
                for (j = 0; j < 5; j++)
                    if (fabs(x[j] - x[j+1]) >4)
                    {
                        flag1 = 0;
                        break;
                    }
                for (j = 0; j < 4; j++)
                    if (x[j] - x[j+1] == 0 && x[j] - x[j+2] == 0)
                    {
                        flag2 = 0;
                        break;
                    }
                if (flag1 == 1 && flag2 == 1 && flag3 == 1)
                {
                    for (j = 0; j < 6; j++)
                        printf("%c",x[j]);
                    printf("
    ");
                }
            }
            printf("
    ");
        }
        return 0;
    }
            

    779、

    兰州烧饼

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    烧饼有两面,要做好一个兰州烧饼,要两面都弄热。当然,一次只能弄一个的话,效率就太低了。有这么一个大平底锅,一次可以同时放入k个兰州烧饼,一分钟能做好一面。而现在有n个兰州烧饼,至少需要多少分钟才能全部做好呢?
    输入
    依次输入n和k,中间以空格分隔,其中1 <= k,n <= 100000
    输出
    输出全部做好至少需要的分钟数
    样例输入
    3 2
    样例输出
    3
    提示
    如样例,三个兰州烧饼编号a,b,c,首先a和b,然后a和c,最后b和c,3分钟完成
    上传者
    勿念情
    #include<stdio.h>
    int main() {
    	int n, k;
    	while (scanf("%d%d", &n, &k) != EOF) {
    		if (n < k)
    			printf("2
    ");
    		else {
    			if (2 * n % k == 0)
    				printf("%d
    ", 2 * n / k);
    			else
    				printf("%d
    ", 2 * n / k + 1);
    		}
    	}
    	return 0;
    }

    811、

    变态最大值

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述

    Yougth讲课的时候考察了一下求三个数最大值这个问题,没想到大家掌握的这么烂,幸好在他的帮助下大家算是解决了这个问题,但是问题又来了。

    他想在一组数中找一个数,这个数可以不是这组数中的最大的,但是要是相对比较大的,但是满足这个条件的数太多了,怎么办呢?他想到了一个办法,把这一组数从开始把每相邻三个数分成一组(组数是从1开始),奇数组的求最大值,偶数组的求最小值,然后找出这些值中的最大值。

    输入
    有多组测试数据,以文件结束符为标志。
    每组测试数据首先一个N,是数组中数的个数。(0<N<10000,为降低题目难度,N是3的倍数)
    然后是数组中的这些数。
    输出
    输出包括一行,就是其中的最大值。
    样例输入
    3
    4 5 6
    6
    1 2 3 7 9 5
    
    样例输出
    6
    5
    来源
    Yougth原创
    上传者
    TC_杨闯亮
     
    #include "iostream"
    using namespace std;
    int max1(int a,int b,int c)//我去,这里用的max,尼玛
    {
        int t;
    	if(a>b){t=a;a=b;b=t;}
    	if(a>c){t=a;a=c;c=t;}
    	if(b>c){t=b;b=c;c=t;}
    	return c;
    }
    int min1(int x,int y,int z)
    {
        int m;
    	if(x>y){m=x;x=y;y=m;}
    	if(x>z){m=x;x=z;z=m;}
    	if(y>z){m=y;y=z;z=m;}
    	return x;
    }
    int main(int argc, char const *argv[])
    {
    	int n,i,d[10001],e[4000];
    	while(cin>>n)
    	{
    		int max=0;
    		for(i=1;i<=n;i++)
    		{
    			cin>>d[i];
    		}
    		for(i=3;i<=n;i+=3)
    		{
    			if((i/3)%2==1)
    			{
    				e[i/3]=max1(d[i-2],d[i-1],d[i]);
    			}
    			if((i/3)%2==0)
    			{
    				e[i/3]=min1(d[i-2],d[i-1],d[i]);
    			}
    		}
    		max=e[1];
    		for(i=2;i<=n/3;i++)
    			if(e[i]>max) max=e[i];
    		cout<<max<<endl;
    	}
    	return 0;
    }
      
    #include <cstdio>//最优程序
    #define Max(a,b,c) a>(b>c?b:c)?a:(b>c?b:c)
    #define Min(a,b,c) a>(b>c?c:b)?(b>c?c:b):a
    int main()
    {
        int a[10005];
        int n,i,j,h;
        while(~scanf("%d",&n))
        {
            int max=1<<32;
            for(i=0;i<n&&scanf("%d",&a[i]);i++){}
            for(i=0;i<n;i+=3){
                h=i%2==0?Max(a[i],a[i+1],a[i+2]):Min(a[i],a[i+1],a[i+2]);
                max=h>max?h:max;
            }
            printf("%d
    ",max);
        }
        return 0;
    }               

    813、

    对决

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述

    Topcoder 招进来了 n 个新同学,Yougth计划把这个n个同学分成两组,要求每组中每个人必须跟另一组中每个同学进行一次算法对决,问存不存在一种分组方式在k场完成对决。(两组中每一组中人数都要大于0)

    输入
    有多组测试数据,每组测试数据两个数 n 和 k ,n和k都为0时表示输入结束。(0<n<10000,0<k<1000000)
    输出
    输出一行,如果可以,输出YES,不行的话输出NO。
    样例输入
    4 1
    4 3
    4 4
    2 1
    3 3
    0 0
    样例输出
    NO
    YES
    YES
    YES
    NO
    提示
    4个人分成两组,1和3则需对决3场,2和2则需对决4场。
    来源
    Yougth原创
    上传者
    TC_杨闯亮
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
        int i,n,k;
        while(scanf("%d%d",&n,&k),n,k)
        {
            int jt=0;
            for(i=0; i<n; i++)
            {
                if(k==i*(n-i))
                {
                    printf("YES
    ");
                    jt=1;
                    break;
                }
            }
            if(jt==0)
                printf("NO
    ");
        }
        return 0;
    }   
     
    #include <cstdio>//最优程序
    
    int main()
    {
        int n,k;
        while(scanf("%d%d",&n,&k)&&(n||k))
        {
            int ok=0;
            for(int i=1;i<=n/2;i++)
            {
                if(i*(n-i)==k)
                    ok=1;continue;
            }
            if(ok)
                printf("YES
    ");
            else
                printf("NO
    ");
        }
        return 0;
    }             

    822、

    画图

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述
    计算机画图也挺有趣的哈!那我们就来用计算机画幅图吧。。。
    输入
    输入一个正整数N(0<N<=10),表示要输出的正方形的边上*的个数
    输出
    输出一个满足题意的正方形
    样例输入
    4
    样例输出
    ****
    ****
    ****
    ****
    上传者
    TC_赵坤垚
     
    #include "stdio.h"
    int main(int argc, char const *argv[])
    {
        int n,i,j;
        scanf("%d",&n);
        for (i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
            {
                printf("*");
            }
            printf("
    ");
        }
        return 0;
    }
            

    833、

    取石子(七)

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述

    Yougth和Hrdv玩一个游戏,拿出n个石子摆成一圈,Yougth和Hrdv分别从其中取石子,谁先取完者胜,每次可以从中取一个或者相邻两个,Hrdv先取,输出胜利着的名字。

    输入
    输入包括多组测试数据。
    每组测试数据一个n,数据保证int范围内。
    输出
    输出胜利者的名字。
    样例输入
    2
    3
    
    样例输出
    Hrdv
    Yougth
    来源
    Poj
    上传者
    TC_杨闯亮
    #include <stdio.h>
    int main(void) {
    	int n;
    	while (scanf("%d", &n) != EOF) {
    		if (n < 3)
    			printf("Hrdv
    ");
    		else
    			printf("Yougth
    ");
    	}
    }
     
    #include<cstdio>
    int n;
    int main()
    {
        while(~scanf("%d",&n))
            printf(n>=3?"Yougth
    ":"Hrdv
    ");
        return 0;
    }        

    844、

    A+B Problem(V)

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述
    做了A+B Problem之后,Yougth感觉太简单了,于是他想让你求出两个数反转后相加的值。帮帮他吧
    输入
    有多组测试数据。每组包括两个数m和n,数据保证int范围,当m和n同时为0是表示输入结束。
    输出
    输出反转后相加的结果。
    样例输入
    1234 1234
    125 117
    0 0
    样例输出
    8642
    1232
    来源
    Yougth原创
    上传者
    TC_杨闯亮
    #include <stdio.h>
    
    /* 整数反转 */
    long long rev(int a) {
    	long long s = 0;
    
    	while (a) {
    		s = s * 10 + a % 10;
    		a /= 10;
    	}
    	return s;
    }
    
    int main(void) {
    	int m, n;
    	long long M, N;
    
    	while (1) {
    		scanf("%d%d", &m, &n);
    		if (m == 0 && n == 0)
    			break;
    		printf("%lld
    ", rev(m) + rev(n));
    	}
    	return 0;
    }
     
    #include <iostream>//最优程序
    #include <string>
    using namespace std;
    int main()
    {
        string s,t;
        int x,y;
        while(cin>>s>>t)
        {
            int x=0,y=0;
            if(s[0]=='0'&&t[0]=='0')
                break;
            for(int i=s.size()-1;i>=0;i--)
                x=x*10+(s[i]-'0');
            for(int i=t.size()-1;i>=0;i--)
                y=y*10+(t[i]-'0');
            cout<<x+y<<endl;
        }
        return 0;
    }       
    

    845、

    无主之地1

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述
    子 晓最近在玩无主之地1,他对这个游戏的评价不错,结合了FPS与RPG元素,可玩度很高。不过,他发现了一代的任务系统做的不好,任务系统并没有帮他统计 清楚哪个区域有多少任务,而且,给任务的时候呢,也比较散乱。比如,在1区域的一个任务点,你领到了4个任务;2区域的一个任务点,你领到了3个任务;游 戏一段时间后,你又在1区域另一个任务点个领到了3任务(之前任务没有完成),3区域领到了9个任务……他感觉很凌乱,现在他要设计一个程序来统计每个区 域有多少个任务。
    输入
    多组测试数据,以输入0 0结束
    每组数据占一行,输入m区域,n个任务(0<m,n<100)
    输出
    输出各个区域的统计结果(不要求排序)
    样例输入
    1 3
    2 3
    3 4
    1 7
    0 0
    样例输出
    1 10
    2 3
    3 4
    来源
    原创
    上传者
    TC_高金
     
    #include <stdio.h>
    
    int main()
    {
        int m,n,i,j;
        int a[100]= {0};
        int c[100]= {0},k=0;
        while(scanf("%d %d",&m,&n)&&m&&n)
        {
            a[m]+=n;
            c[k++]=m;
        }
        for(i=0; i<k-1; i++)
        {
            for(j=i+1; j<k; j++)
            {
                if(c[i]==c[j])
                    c[j]=0;
            }
        }
        for(i=0; i<k; i++)
        {
            if(c[i]!=0)
            {
                printf("%d %d
    ",c[i],a[c[i]]);
                c[i]=0;
            }
        }
        return 0;
    }
            

    975、

    关于521

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:2
    描述

    Acm队的流年对数学的研究不是很透彻,但是固执的他还是想一头扎进去。

    浏 览网页的流年忽然看到了网上有人用玫瑰花瓣拼成了521三个数字,顿时觉得好浪漫,因为每个男生都会不经意的成为浪漫的制造者。此后,流年走到哪里都能看 到5、2、1三个数字,他怒了,现在他想知道在连续的数中有多少数全部包含了这三个数字。例如12356就算一个,而5111就不算。特别的,如果他看到 了521三个数连续出现,会特别的愤怒。例如35210。

    输入
    多组测试数据:
    一行给定两个数a,b(0<a,b<1000000),表示数字的开始和结束。
    输出
    一行显示他想要知道的数有几个及显示有多少个数字令他特别的愤怒。用空格隔开。
    样例输入
    200 500300 9001 600
    样例输出
    Case 1:2 0Case 2:2 1Case 3:6 1
    来源
    流年
    上传者
    ACM_安鹏程
     
    #include <iostream>
    #include <string.h>
    using namespace std;
    int array[2][1000010];
    int main()
    {
        int a, b, c;
        int cnt = 0, cntp = 0;
        memset(array, 0, sizeof(array));
        for (int i = 1; i <= 1000000; i++)
        {
            a = b = c = 0;
            if ((i/100000)%10 == 1 || (i/10000)%10 == 1
                    || (i/1000)%10 == 1 || (i/100)%10 == 1 || (i/10)%10 == 1 || i%10 == 1)
                a = 1;
            if ((i/100000)%10 == 2 || (i/10000)%10 == 2
                    || (i/1000)%10 == 2 || (i/100)%10 == 2 || (i/10)%10 == 2 || i%10 == 2)
                b = 1;
            if ((i/100000)%10 == 5 || (i/10000)%10 == 5
                    || (i/1000)%10 == 5 || (i/100)%10 == 5 || (i/10)%10 == 5 || i%10 == 5)
                c = 1;
            if (a && b && c)
                ++cnt;
            if ((i/1000)%1000 == 521 || (i/100)%1000 == 521
                    || (i/10)%1000 == 521 || (i%1000) == 521)
                ++cntp;
            array[0][i] += cnt;
            array[1][i] += cntp;
        }
        int x, y, ca = 0;
        while (cin >> x >> y)
        {
            cout << "Case " << ++ca << ":";
            cout << array[0][y] - array[0][x-1] << " "
                 << array[1][y] - array[1][x-1] << endl;
        }
        return 0;
    }   
     
    #include<stdio.h>//最优程序
    int a[2][1000001]={0};
    int main()
    {
    int k=0,i,sum=0;
    for(i=1;i<=1000000;i++)
    {
    if((i%10==5||(i/10)%10==5||(i/100)%10==5||(i/1000)%10==5||(i/10000)%10==5||(i/100000)%10==5)&&(i%10==2||(i/10)%10==2||(i/100)%10==2||(i/1000)%10==2
    ||(i/10000)%10==2||(i/100000)%10==2)&&(i%10==1||(i/10)%10==1||(i/100)%10==1||(i/1000)%10==1||(i/10000)%10==1||(i/100000)%10==1))
    {sum++;
    if(i/1000==521||(i/100)%1000==521||(i/10)%1000==521||i%1000==521)k++;}
    a[0][i]+=sum;
    a[1][i]+=k;
    }
    int m,n,w=0;
    while(scanf("%d%d",&n,&m)!=EOF)
    printf("Case %d:%d %d
    ",++w,a[0][m]-a[0][n-1],a[1][m]-a[1][n-1]);
    }             

    1071、

    不可以!

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
    描述

    判断:两个数x、y的正负性。

    要求:不可以使用比较运算符,即"<",">","<=",">=","==","!="

    输入
    有多组数据,每组数据占一行,每一行两个数x,y。
    x、y保证在int范围内。
    输出
    每组数据输出占一行。
    如果两个数是一正一负,输出"Signs are opposite"
    如果是同为正或同为负,输出"Signs are not opposot"
    如果无法确定,输出"Signs can't be sure"
    输出不包括引号
    样例输入
    1 1
    -1 1
    
    样例输出
    Signs are not opposot
    Signs are opposite
    提示
    如对本题有何疑问,请到讨论区提问或邮件我!
    来源
    爱生活
    上传者
    TCM_张鹏
     
    /*
     * http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1071
     * by jtahstu on 2015/2/11 15:00 
     * copy csdn 听自己心跳的声音 
     * http://blog.csdn.net/u013634213/article/details/40055329
     */
    #include<cstdio>
    #include<cstring>
    int main() {
    	int a, b;
    	while (scanf("%d%d", &a, &b) != EOF) {
    		if (!(a * b)) {
    			puts("Signs can't be sure");
    			continue;
    		}
    		if ((a >> 31) ^ (b >> 31))
    			puts("Signs are opposite");
    		else
    			puts("Signs are not opposot");
    	}
    	return 0;
    }
      
    #include<stdio.h>//最优程序
    int main()
    {
        int a,b,c;
        while(~scanf("%d%d",&a,&b))
        {
            c=((a>>31)&1)+((b>>31)&1);
            if((!a)||(!b))printf("Signs can't be sure
    ");
            else printf("Signs are %s
    ",c&1?"opposite":"not opposot");
        }
    }        
           

    1092、

    数字分隔(二)

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:3
    描述

    在一个遥远的国家,银行为了更快更好的处理用户的订单,决定将一整串的数字按照一定的规则分隔开来,分隔规则如下:

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

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

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

    输入
    多组测试数据,每行输入一个实数n(n的位数小于100)
    输出
    输出分隔后的结果
    样例输入
    00012345670.0000-10005.1645
    样例输出
    1,234,567.000.00(10,005.16)
    来源
    calamity_coming
    上传者
    ACM_孙毓阳
     
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()
    {
        char s[110],t[110],r[110];
        while(cin>>s)
        {
            memset(r,'',sizeof(r));
            memset(t,'',sizeof(t));
            int i,l,poi=0,dis,car,k=0,f=1,j=0;
            l=strlen(s);
            for(i=s[0]=='-'?1:0; i<l; i++)//处理原字符串
            {
                if(s[i]!='0'&&f)
                {
                    if(s[i]=='.')
                        t[j++]='0';
                    f=0;
                }
                if(s[i]=='0'&&f) continue;
                else t[j++]=s[i];
            }
            if(!j) {
                    t[j++]='0';f=0;//判断当原字符串为0时的情况
            }
            for(i=0; i<j; i++)
            {
                if(t[i]=='.')
                {
                    poi=i;//找出小数点的位置
                    f=1;//如果有小数点,则f置1
                    break;
                }
            }
            if(f)//当字符串有小数点时
            {
                dis=j-1-poi;//计算小数点到字符串末尾的距离
                if(dis==2) for(i=j-1; i>=0; i--)r[k++]=t[i];//如果只有两位小数,原样输出
                else if(dis==1)//如果有一位小数,则最后一位补0
                {
                    r[k++]='0';
                    for(i=j-1; i>=0; i--) r[k++]=t[i];
                }
                else//如果距离大于2
                {
                    if(t[poi+3]<'5') for(i=poi+2; i>=0; i--)r[k++]=t[i];//如果第三位小数小于5
                    else//如果第三位小数大于5
                    {
                        car=1;
                        for(i=poi+2; i>=0; i--)
                        {
                            if(t[i]=='.')
                            {
                                r[k++]=t[i];
                                continue;
                            }
                            if(car) t[i]+=1;
                            if(t[i]>'9')
                            {
                                t[i]='0';
                                car=1;
                            }
                            else car=0;
                            r[k++]=t[i];
                        }
                        if(t[0]=='0')
                            r[k++]='1';
                    }
                }
            }
            else for(i=j-1; i>=0; i--)r[k++]=t[i];//没有小数点,原样输出
            if(s[0]=='-')//如果是负数
            {
                if(!f)
                {
                    cout<<'(';//负数需要在字符串前后加上括号
                    for(i=k-1; i>=0; i--)
                    {
                        cout<<r[i];
                        if(i%3==0&&i) cout<<',';//控制','的位置
                    }
                    cout<<".00"<<')'<<endl;//没有小数点,补上小数点和两位零
                }
                else
                {
                    cout<<'(';
                    for(i=k-1; i>=0; i--)
                    {
                        cout<<r[i];
                        if(i%3==0&&i>3) cout<<',';
                    }
                    cout<<')'<<endl;
                }
            }
            else
            {
                if(!f)
                {
                    for(i=k-1; i>=0; i--)
                    {
                        cout<<r[i];
                        if(i%3==0&&i) cout<<',';
                    }
                    cout<<".00"<<endl;
                }
                else
                {
                    for(i=k-1; i>=0; i--)
                    {
                        cout<<r[i];
                        if(i%3==0&&i>3) cout<<',';
                    }
                    cout<<endl;
                }
            }
        }
    }        

    1104、

    就我不坑

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
    描述

    as we all know ,就我不坑,呵呵,当然,这次我还是不坑,我只让你帮我翻译一下数字即可。

    所谓翻译,就是将一个数字用中文读出来,很简单吧,快快AC吧。

    数字的中文表示分别为:零、壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿.

    输入
    int 范围内,保证没错,EOF。
    输出
    用我给你的中文写出来就好了
    样例输入
    10
    1052
    10000
    样例输出
    壹拾
    壹仟零伍拾贰
    壹万
    
    提示
    我真的不坑。
    来源
    你管我呢
    上传者
    ACM_刘炀
     
    这题换题了,之前不是这题目,所以就粘贴了一份来
     
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char ch[20];
        int len,i,k,t,p;
        while(scanf("%s",ch)!=EOF)
        {
            k=0;p=1;
            len=strlen(ch);
            for(i=0;i<len;i++)
            {
                t=len-k;
                if(ch[i]=='0'&&(t-1)%4!=0&&ch[i+1]!='0'||ch[0]=='0')    printf("零");
                if(ch[i]=='1')    printf("壹");
                if(ch[i]=='2')    printf("贰");
                if(ch[i]=='3')    printf("叁");
                if(ch[i]=='4')    printf("肆");
                if(ch[i]=='5')    printf("伍");
                if(ch[i]=='6')    printf("陆");
                if(ch[i]=='7')    printf("柒");
                if(ch[i]=='8')    printf("捌");
                if(ch[i]=='9')    printf("玖");
                if(ch[i]!='0'||(t-1)%4==0)
                {
                    if(t==10)    printf("拾");
                    if(t==9)    printf("亿"); 
                    if(t==8)    printf("仟");
                    if(t==7)    printf("佰");
                    if(t==6)    printf("拾");
                    if(t==5&&(ch[k]!='0'||ch[k-1]!='0'||ch[k-2]!='0'||ch[k-3]!='0'))    printf("万");
                    if(t==4)    printf("仟");
                    if(t==3)    printf("佰");
                    if(t==2)    printf("拾");
                    
                }
                k++; 
            }
            printf("
    ");
        }
        
        return 0;
    }               

               OK,本文到此也就结束了,也花了本人好几个小时的时间,但AC这些题却用了好几个月,花了相当长的时间,也是边刷边学习,不断改进,下次再写汇总也不知何年何月了,但还会写其他的,马上学java了,又有的写了,慢慢来。

  • 相关阅读:
    configure.ac:91: error: possibly undefined macro: AC_SEARCH_LIBS
    debian上安装tmux
    ssh: Bad configuration option: usedns
    mysql启动失败“MySQL Daemon failed to start”
    批量查询文件的编码格式
    mysql计算QPS
    网络资源汇总
    jQuery Mobile + HTML5
    配置SQL Server 2008 R2 Reporting Services
    分享一个C#创建Barcode的DLL
  • 原文地址:https://www.cnblogs.com/jtahstu/p/4288547.html
Copyright © 2011-2022 走看看