# acmer之路（3）四月第一周日志

ID 2015 偶数求和

#include<stdio.h>

int main()
{
int n, m, k;
int i,j;
int a[101];
a[0] = 0;
int sum, sum1;
int count;
while (scanf("%d", &n) != EOF)
{
for (i = 1; i <= n; i++)
{
a[i] = 2 * i;
}
scanf("%d", &m);
count = 0;
for (i = 1; i <= n; i = i + m)
{
sum = 0;
for (j = 0; j < m; j++)
{
sum = sum + a[i + j];
}
sum = sum / m;
printf("%d", sum);
if ((i + j - 1) < n)
{
printf(" ");
}
if ((i + j - 1) == n)
{
printf("\n");
}
count++;
if ((n - m * count) < m) break;
}
sum1 = 0;
if ((n - m * count) < m && (n - m * count) > 0)
{
k = n - m * count;
for (i = 0; i < k; i++)
{
sum1 = sum1 + a[m*count + i + 1];
}
sum1 = sum1 / k;
printf("%d\n", sum1);
}
}
}

ID 2016 数据的交换输出

#include<stdio.h>
#define N 100
int main() {
int arr[N];
int i,x,n;
while(scanf("%d",&n),n!=0) {
for(i=0; i<n; i++)
scanf("%d",&arr[i]);
int k=0,j=arr[0];
for(i=1; i<n; i++) {
if(j>arr[i]) {
j=arr[i];
k=i;
}
}
x=arr[0];
arr[0]=j;
arr[k]=x;
for(i=0; i<n; i++) {
if(i==n-1)
printf("%d",arr[i]);
else
printf("%d ",arr[i]);
}
printf("\n");
}
return 0;
}

ID 2017 字符串统计

#include<stdio.h>
#include<string.h>
main()
{
int n,num;
char str;
scanf("%d",&n);
getchar();
while(n--)
{         num=0;
while(scanf("%c",&str),str!='\n')//
{
if(str>='0'&&str<='9') num++;
}
printf("%d\n",num);
}
return 0;

}

ID 2019 数列有序

#include<stdio.h>
int main() {
int i,j,k,m,n;
while(scanf("%d %d",&n,&m),n!=0||m!=0) {
int a[120];
for(i=0; i<n; i++)
scanf("%d",&a[i]);
a[n]=m;
for(j=n-1; j>=0; j--) {
if(a[j]>a[j+1]) {
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
} else
break;
}
for(i=0; i<=n; i++) {
if(i==0)
printf("%d",a[i]);
else
printf(" %d",a[i]);
}
printf("\n");
}
return 0;
}

ID 2021 发工资喽

#include<stdio.h>
int main()
{
int n;
int a[101], b[101];
int i;
int hundreds, tens, nums;
int money;
int sum;
while (scanf("%d", &n), n != 0)
{
sum = 0;
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++)
{
money = 0;
b[i] = 0;
hundreds = a[i] / 100;
tens = (a[i] % 100) / 10;
nums = (a[i] % 100) % 10;
if (hundreds > 0)
{
money = money + hundreds;
}
if (tens >= 5)
{
money++;
tens = tens - 5;
money = money + tens;
}
else
{
money = money + tens;
}
if (nums >= 5)
{
money++;
nums = nums - 5;
money = money + nums / 2;
money = money + nums % 2;
}
else
{
money = money + nums / 2;
money = money + nums % 2;
}
b[i] = money;
}
for (i = 0; i < n; i++)
{
sum = sum + b[i];
}
printf("%d\n", sum);
}
return 0;
}

ID 2022 海选女主角

#include <stdio.h>
#include <math.h>

int main() {

int n, m, i, j, a, b;
double d, max;
while(~scanf("%d%d", &m, &n)) {

max = 0;
a = 0;
b = 0;
for(i=0; i<m; i++)
for(j=0; j<n; j++) {
scanf("%lf", &d);
if(fabs(d) > fabs(max)) {
a = i;
b = j;
max = d;
}
}

printf("%d %d %.0lf\n", a+1, b+1, max);
}

return 0;
}

ID 2023 求平均成绩

#include<stdio.h>
int main() {
int n,m;
double a1[50][5],av1[50],av2[5],k;
while(scanf("%d %d",&n,&m)==2) {
int x,y=0;
for(int pe=0; pe<n; pe++) {
for(int su=0; su<m; su++)
scanf("%lf",&a1[pe][su]);
}
for(int i=0; i<n; i++) {
k=0;
for(int j=0; j<m; j++)
k+=a1[i][j];
av1[i]=k/m;
}
for(int i=0; i<m; i++) {
k=0;
for(int j=0; j<n; j++)
k+=a1[j][i];
av2[i]=k/n;
}
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(a1[i][j]>=av2[j])
x=1;
else {
x=0;
break;
}
}
if(x==1)
y++;
}
for(int i=0; i<n; i++) {
if(i==n-1)
printf("%.2lf\n",av1[i]);
else
printf("%.2lf ",av1[i]);
}
for(int j=0; j<m; j++) {
if(j==m-1)
printf("%.2lf\n",av2[j]);
else
printf("%.2lf ",av2[j]);

}
printf("%d\n",y);
printf("\n");
}
return 0;
}

ID 2024 合法标识符

#include<stdio.h>
#include<string.h>

int main()
{
char a[50];
int t;
scanf("%d\n",&t);
while(t--)
{
gets(a);
if(!isalpha(a[0])&&a[0]!='_')
{
printf("no\n");
continue;
}
int flag=1;
int l=strlen(a);
for(int i=1;i<l;i++)
{
if(a[i]!='_'&&!isalnum(a[i]))
{
flag=0;
break;
}
else
{
flag=1;
}
}
if(flag==1)
{
printf("yes\n");
}
else if(flag==0)
{
printf("no\n");
}
}
return 0;
} 

ID 2026 首字母变大写

#include<stdio.h>
#include<string.h>
int main()
{
char a[120];
int k, i;
while (gets_s(a,120) != NULL)
{
k = strlen(a);
a[0] = a[0] - 32;
for (i = 0; i < k; i++)
{
if (a[i] == ' ')
{
a[i + 1] = a[i + 1] - 32;
}
}
puts(a);
}
return 0;
}

get_s()函数是新标准里面的一个函数，它避免了get()函数数据溢出导致覆盖堆栈中原有数据的问题。

ID 2027 统计元音

#include<stdio.h>
#include<string.h>
int main()
{
char a[120];
int n, i, k;
int count1, count2, count3, count4, count5;
scanf("%d", &n);
getchar();
while (n--)
{
count1 = count2 = count3 = count4 = count5 = 0;
gets_s(a, 120);
k = strlen(a);
for (i = 0; i < k; i++)
{
if (a[i] == 'a')
{
count1++;
}
if (a[i] == 'e')
{
count2++;
}
if (a[i] == 'i')
{
count3++;
}
if (a[i] == 'o')
{
count4++;
}
if (a[i] == 'u')
{
count5++;
}
}
printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n", count1, count2, count3, count4, count5);
if (n)
{
printf("\n");
}
}

return 0;
}

ID 2028 求最小公倍数

#include<stdio.h>
#include<string.h>
int main()
{
long long n;
long long i;
long long a[10001];
long long num1, num2;
long long remainder;
long long temp;
long long lcm;
long long x, y;
while (scanf("%d", &n) != EOF)
{

num1 = num2 = 0;
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
lcm = a[0];
for (i = 1; i < n; i++)
{
num1 = lcm;
num2 = a[i];
if (num1 < num2)
{
temp = num2;
num2 = num1;
num1 = temp;
}
x = num1;
y = num2;
while (y != 0)
{
temp = x % y;
x = y;
y = temp;
}
lcm = num1 * num2 / x;
}
printf("%d\n", lcm);
}
return 0;
}

ID 2030 汉字统计

#include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d", &n);
getchar();
while (n--)
{
char a[110000];
gets_s(a,110000);
int l, num = 0;
l = strlen(a);
for (int i = 0; i<l; i++)
{
if (a[i]<' ')
num++;
}
printf("%d\n", num / 2);
}
return 0;
}

ID 2032 杨辉三角

#include <stdio.h>
int main() {
int s = 1, n;
int i, j;
while(scanf("%d", &n)!=EOF) {
printf("1\n");
for (i = 2; i <= n; s = 1, i++) {
printf("1 ");
for (j = 1; j <= i - 2; j++)
printf("%d ", (s = (i - j) * s / j));
printf("1\n");
}
printf("\n");
}
return 0;
}

ID 2033 时间相加

#include<stdio.h>
#include<string.h>
int main()
{
int n;
int a[100][6];
int i;
int hour, minute, second;
while (scanf("%d", &n) != EOF)
{
for (i = 0; i < n; i++)
{
scanf("%d %d %d %d %d %d", &a[i][0], &a[i][1], &a[i][2], &a[i][3], &a[i][4], &a[i][5]);
}
for (i = 0; i < n; i++)
{
hour = minute = second = 0;
hour = a[i][0] + a[i][3];
if (a[i][1] + a[i][4] > 59)
{
hour = hour + 1;
minute = a[i][1] + a[i][4] - 60;
}
else
{
minute = a[i][1] + a[i][4];
}
if (a[i][2] + a[i][5] > 59)
{
minute = minute + 1;
second = a[i][2] + a[i][5] - 60;
}
else
{
second = a[i][2] + a[i][5];
}
printf("%d %d %d\n", hour, minute, second);
}
}
return 0;
}

so easy!!!

ID 2035 求数后三位

#include<stdio.h>
int main()
{
int m, n;
int temp;
int i;
while (scanf("%d %d", &m, &n), m != 0, n != 0)
{
temp = 1;
for (i = 0; i < n; i++)
{
temp = (temp * m) % 1000;
}
printf("%d\n", temp);
}
return 0;
}

ID 2039 三角形

#include<stdio.h>
int main()
{
int n;
int i, j;
float a[3];
float max;
int index;
float temp;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
max = 0;
for (j = 0; j < 3; j++)
{
scanf("%f", &a[j]);
if (a[j] > max)
{
max = a[j];
index = j;
}
}

temp = a[0];
a[0] = a[index];
a[index] = temp;

if (a[1] + a[2] > a[0])
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}

ID 2040 亲和数

#include<stdio.h>
#include<math.h>
int main()
{
int n;
long num1, num2;
int i;
long sum1, sum2;
while (scanf("%d", &n) != EOF)
{
while (n--)
{
sum1 = sum2 = 0;
scanf("%d %d", &num1, &num2);
for (i = 2; i <= sqrt(num1); i++)
{
if (num1%i == 0)
{
sum1 = sum1 + i + num1/i;
}
}
sum1++;
for (i = 2; i <= sqrt(num2); i++)
{
if (num2%i == 0)
{
sum2 = sum2 + i + num2 / i;
}
}
sum2++;
if ((sum1 == num2) && (sum2 == num1))
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}
return 0;
}

ID 2041 超级楼梯

#include<stdio.h>
#include<math.h>
int main()
{
int n,m;
int a[50];
int i;
while (scanf("%d", &n) != EOF)
{
while (n--)
{
a[0] = 1;
a[1] = 1;
scanf("%d", &m);
for (i = 2; i <= 40; i++)
{
a[i] = a[i - 1] + a[i - 2];
}
printf("%d\n", a[m-1]);
}
}
return 0;
}

ID 2042 过路费

#include<stdio.h>
#include<math.h>
int main()
{
int n,m;
int i;
int initial_value, final_value;
while (scanf("%d", &n) != EOF)
{
while (n--)
{
scanf("%d", &m);
initial_value = 3;
for (i = 0; i < m; i++)
{
final_value = 2 * (initial_value - 1);
initial_value = final_value;
}
printf("%d\n", final_value);
}
}
return 0;
}

ID 2045 着色问题

#include<stdio.h>
int main()
{
int n;
int i;
__int64 coefficient1, coefficient2;
__int64 count;
__int64 temp;
while (scanf("%d", &n)!=EOF)
{
if (n == 1)
{
printf("3\n");
}
else if (n == 2||n == 3)
{
printf("6\n");
}
else
{
coefficient1 = coefficient2 = 2;
count = 0;
for (i = 4; i <= n; i++)
{
count = (coefficient1 * 2 + coefficient2) * 3;
temp = coefficient1;
coefficient1 = coefficient2;
coefficient2 = 2 * temp + coefficient2;
}
printf("%I64d\n", count);
}
}
return 0;

}

29 篇文章20 人订阅

0 条评论

## 相关文章

35460

38950

553130

1.3K70

### SSE图像算法优化系列五：超高速指数模糊算法的实现和优化（10000*10000在100ms左右实现）。

今天我们来花点时间再次谈谈一个模糊算法，一个超级简单但是又超级牛逼的算法，无论在效果上还是速度上都可以和Boxblur, stackblur或者是G...

422100

20450

### 【译文】数据可视化的10个关键术语①

Format 交互方式 Interactive visualisations allow you to modify, manipulate and expl...

34840

93440

45480

13200