杭电oj2020-2029————C语言

  1. 绝对值排序
    http://acm.hdu.edu.cn/showproblem.php?pid=2020
#include 
#include 
int main()
{
    int i,n,t;int a[100];
    while(~scanf("%d",&n)){
        if(n==0) break;
        for(i=1;i<=n;i++)
            {scanf("%d",&a[i]);}

        for(i=1;i<n;i++)//排序
            for(int j=i+1;j<=n;j++)
                if(fabs(a[i])<fabs(a[j]))
                    {t=a[i];a[i]=a[j];a[j]=t;}
        for (i=1;i<=n;i++){
            if(i!=n) printf("%d ",a[i]);
            else printf("%d\n",a[i]);
        }
    }
    return 0;
}
  1. 发工资咯
    http://acm.hdu.edu.cn/showproblem.php?pid=2021
#include
int main()
{
    int i,j,n,t,k,s[6]={100,50,10,5,2,1};
    while(~scanf("%d",&n),n)  //逗号表达式
    {
        for(i=j=k=0;i<n;i++,j=0)
        {
            scanf("%d",&t);
            while(t)
            {
                if(t<s[j]) j++;
                else t-=s[j],k++;
            }
        }
        printf("%d\n",k);
    }
    return 0;
}

2022海选女主角
http://acm.hdu.edu.cn/showproblem.php?pid=2022

#include 
#include 

int main(void)
{
    int i, j;
    int n, m;
    int x, y;
    double a, t;

    while (scanf("%d%d", &n, &m) != EOF)
    {
        a = x = y = 0;
        for (i = 0 ; i < n ; i++)
        {
            for (j = 0 ; j < m ; j++)
            {
                scanf("%lf", &t);
                if (fabs(t) > fabs(a))
                {
                    a = t;
                    x = i;
                    y = j;
                }
            }
        }
        printf("%d %d %.0f\n", x + 1, y + 1, a);
    }

    return 0;
}

2023求平均成绩
http://acm.hdu.edu.cn/showproblem.php?pid=2023

#include
int main(void)
{
    double n, m, a, b;
    int i, j, A, B;
    double e[50][5];
    double f[5];
    while (scanf("%lf %lf", &n, &m) != EOF)
    {
        a = 0;
        b = 0;
        B = 0;
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < m; j++)
            {
                scanf("%lf", &e[i][j]);
            }
        }
        
        for (j = 0; j < n; j++)
        {
            a = 0;
            for (i = 0; i < m; i++)
            {
                a += e[j][i];
            }
            
            if (j == 0)
            {
                printf("%.2f", a/m);
            }
            else
            {
                printf(" %.2f", a/m);
            }
        }
        printf("\n");
        for (i = 0; i < m; i++)
        {
            b = 0;
            for (j = 0; j < n; j++)
            {
                b += e[j][i];
            }
            f[i] = b / n;
            if (i == 0)
            {
                printf("%.2f", f[i]);
            }
            else
            {
                printf(" %.2f",f[i]);
            }
        }
        printf("\n");
        for (i = 0; i < n; i++)
        {
            A = 0;
            for (j = 0; j < m; j++)
            {
                if (e[i][j] >= f[j])
                    A++;
            }
            if (A == m)
                B++;
        }
        printf("%d\n\n", B);
    }
    return 0;
}

2024.C语言合法标识符
http://acm.hdu.edu.cn/showproblem.php?pid=2024

#include 
#include 
 
int main(void)
{
    int n;
    
    scanf("%d", &n);
    getchar();
 
    while (n--) {
        char c, flag = 1;
 
        c = getchar();
 
        if (!(isalpha(c) || c == '_'))
            flag = 0;
 
        while ((c = getchar()) != '\n') {
            if (!(isalnum(c) || c == '_'))
                flag = 0;
        }
 
        printf("%s\n", flag ? "yes" : "no");
    }
 
    return 0;
}
  1. 查找最大元素`
    http://acm.hdu.edu.cn/showproblem.php?pid=2025
#include
#include
int main()
{
	char max,str[101];
	int len,i;
	while(~scanf("%s",str))
	{
		len=strlen(str);
		max='a';
		for(i=0;i<=len-1;i++)
		{
			if(str[i]>max)
			{
				max=str[i];
			}
		}
		for(i=0;i<=len-1;i++)
		{
			printf("%c",str[i]);
			if(str[i]==max)
			{
				printf("(max)");
			}
		}
		printf("\n");
	}
	return 0;
}

  1. 首字母变大写
    http://acm.hdu.edu.cn/showproblem.php?pid=2026
#include 
#include 
#include 
int main()
{
    char a[105];
    int i,len;
    while(gets(a)!='\0')
    {
        len=strlen(a);
        if(a[0]!=' ')
            a[0]=a[0]-32;
        for(i=1;i<len;i++)
        {
            if(a[i]!=' '&&a[i-1]==' ')
            {
                a[i]=a[i]-32;
            }
        }
        puts(a);
    }
    return 0;
}
  1. 统计元音
    http://acm.hdu.edu.cn/showproblem.php?pid=2027
# include 
# include 

int main()
{
    int n, len;
    char s[150];
    while(scanf("%d", &n) != EOF && n != 0)
    {
        getchar();
        while(n--)
        {
            gets(s);
            int a_count = 0;int e_count = 0;int i_count = 0;int o_count = 0;int u_count = 0;
            len = strlen(s);
            for(int i=0;i < len; i++)
            {
                if(s[i] == 'a') a_count += 1;
                if(s[i] == 'e') e_count += 1;
                if(s[i] == 'i') i_count += 1;
                if(s[i] == 'o') o_count += 1;
                if(s[i] == 'u') u_count += 1;
            }
            printf("a:%d\n", a_count);
            printf("e:%d\n", e_count);
            printf("i:%d\n", i_count);
            printf("o:%d\n", o_count);
            printf("u:%d\n", u_count);
            if(n)   printf("\n");

        }
    }
    return 0;
}
  1. Lowest Common Multiple Plus(最小公倍数)
    http://acm.hdu.edu.cn/showproblem.php?pid=2028
//最小公倍数 = 两整数 / 最大公约数
#include 
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b)
{
    return a*b/gcd(a,b);
}
int main()
{
    int a[100],n;
    while(scanf("%d",&n)==1)
    {
        int i,y=1;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
            
        //转换成两个比较,比较n-1轮
        for(i=0;i<n-1;i++)
        {
            a[i+1]=lcm(a[i],a[i+1]);
        }
        printf("%d\n",a[i]);
    }

    return 0;
}
  1. Palindromes _easy version(回文串)
    http://acm.hdu.edu.cn/showproblem.php?pid=2029
#include 
#include 
 
int main(void)
{
    int n, flag, start, end;
    char a[4096];
 
    scanf("%d", &n);
    while(n--) {
        // 读入字符串
        scanf("%s", a);
 
        // 判断是否为回文
        start = 0;
        end = strlen(a) - 1;
        flag = 1;
        while(start < end) {
            if(a[end] != a[start]) {
                flag = 0;
                break;
            }
            start++;
            end--;
        }
 
        // 输出结果
        if(flag)
            printf("yes\n");
        else
            printf("no\n");
    }
 
    return 0;
}

你可能感兴趣的:(c语言)