HDU acm oj 2021-2030 c语言

2021

#define _CRT_SECURE_NO_WARNINGS 1
#include
int main()
{
	int n;
	int N[100];
	int m=0;
	int t;
	scanf("%d", &n);
	while (n != 0) {
		for (int i = 0; i < n; i++) {
			scanf("%d", &N[i]);
		}
		for (int i = 0; i < n; i++) {
				t = N[i] / 100;
				m += t;
				t = N[i] - t * 100;
				m += t/50;
				t = t - t / 50 * 50;
				m += t / 10;
				t = t - t / 10 * 10;
				m += t / 5;
				t = t - t / 5 * 5;
				m += t / 2;
				t = t - t / 2 * 2;
				m += t / 1;
				t = 0;
		}
		printf("%d", m);
		m = 0;
		scanf("%d", &n);
	}
}

2022

#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
int main()
{
	int m, n;
	int N[50][50];
	int t;
	int I=0, J=0;
	while (scanf("%d %d", &m, &n) != EOF) {
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				scanf("%d", &N[i][j]);
			}
		}
		t = N[0][0];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (abs(N[i][j]) > abs(t))
					t = N[i][j];
			}
		}
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (abs(N[i][j]) == abs(t)) {
					I = i+1;
					J = j+1;
					break;
				}
			}
			if (I != 0)
				break;
		}
		printf("%d %d %d", I, J, t);
		I = 0;
		J = 0;
	}
}

2023

#define _CRT_SECURE_NO_WARNINGS 1
#include
int main() {
	int n, m;
	int N[50][50];
	double M[50];
	double sum=0;
	int t=0,s=0;
	while (scanf("%d %d", &n, &m)!=EOF) {
		for (int i = 0; i < 50; i++) {
			for (int j = 0; j < 50; j++) {
				N[i][j] = 0;
			}
		}
		for (int i = 0; i < 50; i++) {
			M[i] = 0;
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				scanf("%d", &N[i][j]);
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				sum += N[i][j];
			}
			printf("%.2lf ", sum / m);
			sum = 0;
		}
		printf("\n");
		for (int j = 0; j < m; j++) {
			for (int i = 0; i < n; i++) {
				sum += N[i][j];
			}
			M[j] = sum / n;
			printf("%.2lf ", M[j]);
			sum = 0;
		}
		printf("\n");
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (N[i][j] >= M[j]) {
					t++;
				}
			}
			if (t == m)
				s++;
			t = 0;
		}
		printf("%d", s);
		t = 0;
		s = 0;
	}
}

2024

#include
#include//在使用字符串处理函数时,应当在程序文件的开头加入此头文件
int main()
{
	int n, i, j = 1;
	char a[50];
	int t = 0;
	while (scanf("%d", &n) != EOF)
	{
		getchar();//把第一个输入的字符n吸收掉
		while (n--)
		{
			fgets(a,50,stdin);
			while (a[t] != '\n'&&a[t]!='\0') {
				t++;
			}
			if (a[t] == '\n')
				a[t] = '\0';
			if (!(a[0] == '_' || (a[0] >= 'a' && a[0] <= 'z') || (a[0] >= 'A' && a[0] <= 'Z')))//gets()存储字符串到数组时,是从a[0]开始储存的,先判断第一个字符是否是合法字符
				printf("no\n");
			else
			{
				for (i = 1; a[i] != '\0'; i++)//判断完第一个字符后,从啊[1]开始往后逐一判断各个字符是否是合法字符,直到'\0'结束,用gets()存储字符串时会自动在末尾加上'\0'
				{
					if (!(a[i] == '_' || (a[i] >= '0' && a[i] <= '9') || (a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z')))
					{
						printf("no\n");
						break;
					}
				}
				if (i == strlen(a))//如果i的值等于这个字符串的长度,则表明这个字符串的字符都是合法标识符
				{
					printf("yes\n");
				}
			}
		}
	}
	return 0;
}

2025

#define _CRT_SECURE_NO_WARNINGS 1
#include
int main()
{
	char N[100];
	char* p = N;
	char max;
	int i=0;
	while (fgets(N, 100, stdin) != NULL) {
		max = *p;
		while (*p != '\0') {
			if (*p >= max) {
				max = *p;
			}
			p++;
		}
		while (N[i] != '\0') {
			printf("%c", N[i]);
			if (max == N[i])
				printf("(max)");
			i++;
		}
		max = 'A';
		p = N;
		i = 0;
	}
	return 0;
}

2026

#define _CRT_SECURE_NO_WARNINGS 1
#include
int main() {
	char N[100];
	int i = 1;
	int flag = 0;
	while (fgets(N, 100, stdin) != NULL) {
		printf("%c", N[0] - 32);
		while (N[i] != '\0') {
			if (flag == 0)
				printf("%c", N[i]);
			else {
				printf("%c", N[i] - 32);
				flag = 0;
			}
			if (N[i] == ' ')
				flag = 1;
			i++;	
		}
		i = 1;
		flag = 0;
	}
	return 0;
}

2027

#define _CRT_SECURE_NO_WARNINGS 1
#include
int main()
{
	int num1=0, num2=0, num3=0, num4=0, num5=0;
	int n;
	char N[100];
	int j = 0;
	scanf("%d",&n);
	getchar();
	for (int i = 0; i < n; i++) {
		fgets(N, 100, stdin);
		while (N[j] != '\0') {
			switch (N[j]) {
			case 'a':
				num1++;
				break;
			case 'e':
				num2++;
				break;
			case 'i':
				num3++;
				break;
			case 'o':
				num4++;
				break;
			case 'u':
				num5++;
				break;
			}
			j++;
		}
		printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n", num1, num2, num3, num4, num5);
		num1 = 0;
		num2 = 0;
		num3 = 0;
		num4 = 0;
		num5 = 0;
		j = 0;
	}
}

2028

#include
int main() {
	int n;
	long long int sum = 1;
	long long int N[100];
	int t=0;
	while (scanf("%d", &n) != EOF) {
		for (int i = 0; i < n; i++) {
			scanf("%lld", &N[i]);
			sum *= N[i];
		}
		for (int i = 1; i <sum; i++) {
			for (int j = 0; j < n; j++) {
				if (i % N[j] == 0)
					t++;
			}
			if (t == n) {
				printf("%lld", i);
				break;
			}
			else {
				t = 0;
			}
		}
		if (t == 0) {
			printf("%lld", sum);
		}
		sum = 1;
		t = 0;
	}
}

2029

#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
int main() {
	int n;
	char ch[100];
	int t=0;
	int str;
	while (scanf("%d", &n) != EOF) {
		getchar();
		for (int i = 0; i < n; i++) {
			fgets(ch, 100, stdin);
			str = strlen(ch);
			if (str % 2 == 0) {
				for (int i = 0; i < str - 2; i++) {
					if (ch[i] == ch[str - 2-i])
						t++;
				}
				if (t == strlen(ch) - 2 ){
					printf("yes");
				}
				else {
					printf("no");
				}
			}
			else {
				for (int i = 0; i < str - 2; i++) {
					if (ch[i] == ch[str - 2-i])
						t++;
				}
				if (t == strlen(ch) - 2)
					printf("yes");
				else {
					printf("no");
				}
			}
			t = 0;
			getchar();
		}
	}
}

2030

#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
int main() {
	int n;
	char ch[1000];
	int i = 0;
	int t = 0;
	while (scanf("%d", &n) != EOF) {
		getchar();
		for(int j=0;j<n;j++)
		{
			fgets(ch, 1000, stdin);
			while (ch[i] != '\n') {
				if (ch[i] >= 0 && ch[i] <= 127) {
					t++;
				}
				i++;
			}
			printf("%d", (strlen(ch) - 1 - t) / 2);
			t = 0;
			i = 0;
			
		}
	}
}

你可能感兴趣的:(c语言,算法,数据结构)