A.HFUU(easy version)
字符串
#include <stdio.h>
char a[100];
int n = 9, m = 32;
int main()
{
for (int i = 0; i < n; i++)
{
scanf("%s", a + 1); //字符串的读入是不需要加&符号的
//用%s读字符串会读到空格或者换行符为止
puts(a + 1); // puts可以输出一个字符串并且自带换行
}
return 0;
}
字符数组
#include <stdio.h>
char a[100];
int n = 9, m = 32;
int main()
{
for (int i = 0; i < n; i++)
{
scanf("%s", a); //字符串的读入是不需要加&符号的
puts(a);
}
return 0;
}
B.HFUU(hard version)
#include <stdio.h>
#include <string.h>
char a[110];
int n;
int main()
{
scanf("%s", a); //让字符串从下标为1的地方开始
n = strlen(a); // string.h中的函数,用于获取字符串的长度
for (int i = 0; i < n; i++)
{
printf("%c", a[i]);
if (i < 6)
continue; //结束当前轮循环,进入下一轮循环
// ILovehfuuacm
if (a[i - 6] == 'h' && a[i - 5] == 'f' && a[i - 4] == 'u' &&
a[i - 3] == 'u' && a[i - 2] == 'a' && a[i - 1] == 'c' && a[i] == 'm')
{
printf("yyds");
}
}
return 0;
}
C.HFUU(very hard version)
#include <stdio.h>
char a[1000][1000];
int n;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = 1; i <= 13 * n + 19; i++)
{
a[1][i] = a[4 * n + 5][i] = '*';
}
for (int i = 1; i <= 4 * n + 5; i++)
{
a[i][1] = a[i][13 * n + 19] = '*';
}
for (int i = n + 2; i <= 3 * n + 4; i++)
{
a[i][n + 3] = a[i][3 * n + 5] = a[i][4 * n + 7] = a[i][7 * n + 11] = a[i][9 * n + 13] = a[i][10 * n + 15] = a[i][12 * n + 17] = '@';
}
for (int i = n + 3; i <= 3 * n + 5; i++)
{
a[2 * n + 3][i] = '@';
}
for (int i = 4 * n + 7; i <= 6 * n + 9; i++)
{
a[2 * n + 3][i] = a[n + 2][i] = '@';
}
for (int i = 7 * n + 11; i <= 9 * n + 13; i++)
{
a[3 * n + 4][i] = '@';
}
for (int i = 10 * n + 15; i <= 12 * n + 17; i++)
{
a[3 * n + 4][i] = '@';
}
for (int i = 1; i <= 4 * n + 5; i++)
{
for (int j = 1; j <= 13 * n + 19; j++)
{
if (a[i][j] != '@' && a[i][j] != '*')
a[i][j] = '.';
}
}
for (int i = 1; i <= 4 * n + 5; i++)
{
for (int j = 1; j <= 13 * n + 19; j++)
{
printf("%c", a[i][j]);
a[i][j] = '.';
}
puts("");
}
}
return 0;
}
D.浅浅的解个方程
#include <stdio.h>
#define N 20001
#define ll long long
int t,n;
char s[N];
int main()
{
scanf("%d",&t);
while (t--)
{
scanf("%d %s",&n,s);
ll sig = 1,num = 0;
ll liftSum = 0,rightSum = 0;
ll sig_x = 1;
int i;
for (i=0;i<n;++i)
{
if (s[i]=='=')
{
liftSum += sig * num;
break;
}
if (s[i]=='+'||s[i]=='-') liftSum += sig * num;
if (s[i]=='-') sig = -1,num = 0;
else if (s[i]=='+') sig = 1,num = 0;
else if (s[i]=='x') sig_x = sig;
else num *= 10,num += s[i] - '0';
}
sig = 1,num = 0;
for (i=i+1;i<n;++i)
{
if (s[i]=='+'||s[i]=='-') rightSum += sig * num;
if (s[i]=='-') sig = -1,num = 0;
else if (s[i]=='+') sig = 1,num = 0;
else if (s[i]=='x') sig_x = - sig;
else num *= 10,num += s[i] - '0';
if (i==n-1) rightSum += sig * num;
}
//printf("%lld",liftSum);
printf("x=%lld\n",sig_x*(rightSum-liftSum));
}
return 0;
}
E.精打细算的小葛(easy version)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, a, b, p, q, ans = 0;
scanf("%d%d%d%d%d", &n, &a, &b, &p, &q);
for (int i = 1; i <= n; i++)
{
if (i % a == 0 && i % b == 0)
{
if (p > q)
ans += p;
else
ans += q;
continue;
}
if (i % a == 0)
ans += p;
if (i % b == 0)
ans += q;
}
printf("%d", ans);
return 0;
}
F.精打细算的小葛(hard version)
#include <stdio.h>
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
long long n, a, b, p, q, ans = 0;
scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &p, &q);
ans += n / a * p;
ans += n / b * q;
ans -= n / (a * b / gcd(a, b)) * p;
ans -= n / (a * b / gcd(a, b)) * q;
if (p >= q)
ans += n / (a * b / gcd(a, b)) * p;
else
ans += n / (a * b / gcd(a, b)) * q;
printf("%lld\n", ans);
}
return 0;
}
G.单身狗的愤怒
#include <stdio.h>
#define N 1001
int n;
char s[N];
int cnt[26];
int main()
{
scanf("%d",&n);
scanf("%s",s);
int mx = 0;
for (int i=0;i<n;++i)
{
cnt[s[i]-'a'] ++;
if (cnt[s[i]-'a']>mx) mx = cnt[s[i]-'a'];
}
if (mx>(n+1)/2) puts("NO");
else puts("YES");
return 0;
}
H.简单的计算
#include <stdio.h>
int main()
{
long long f = 0, b = 0, tmp;
for (int i = 0; i < 5; i++)
{
scanf("%lld", &tmp);
f += tmp;
}
for (int i = 0; i < 5; i++)
{
scanf("%lld", &tmp);
b += tmp;
}
printf("%lld", f * b);
return 0;
}
I.Brain Power
#include <stdio.h>
#include <stdlib.h>
double score[][5] = {
{1, 1, 0.8, 0.5, 0},
{2, 2, 1.6, 1, 0},
{3, 3, 2.4, 1.5, 0},
{5, 5, 2.5, 2, 0},
{1, 0.5, 0.4, 0.3, 0},
};
int num[5];
int main()
{
double a0 = 0, a = 0, b0 = 0, b = 0, ans;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
scanf("%d", &num[j]);
for (int j = 0; j < 5; j++)
{
a += score[i][0] * num[j];
a0 += score[i][j] * num[j];
}
if (i == 3)
{
for (int j = 0; j < 5; j++)
{
b += score[4][0] * num[j];
b0 += score[4][j] * num[j];
}
}
}
ans = a0 / a * 100 + b0 / b;
printf("%.8lf", ans);
return 0;
}
J.掘地求升
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
if (y < 0)
{
y = -y;
x = -x;
z = -z;
}
if (x < y)
printf("%d", abs(x));
else
{
if (z > y)
printf("-1");
else
printf("%d", abs(z) + abs(x - z));
}
return 0;
}
K.我们是亚军(hard)
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int mx1 = 0, id1, mx2 = 0, id2;
for(int i = 1; i <= (1 << n); i ++)
{
int x;
scanf("%d", &x);
if(i <= (1 << (n - 1)))
{
if(x > mx1)
{
mx1 = x;
id1 = i;
}
}
else
{
if(x > mx2)
{
mx2 = x;
id2 = i;
}
}
}
if(mx1 < mx2) printf("%d\n", id1);
else printf("%d\n", id2);
return 0;
}
L.我们是亚军(easy)
#include <stdio.h>
int a[(1 << 7) + 1], b[(1 << 7) + 1];
int id[(1 << 7) + 1];
int main()
{
int n;
scanf("%d", &n);
int m = (1 << n);
for(int i = 1; i <= m; i ++)
scanf("%d", &a[i]), id[i] = a[i];
for(int i = 1; i <= n - 1; i ++)
{
int cnt = 0;
for(int j = 1; j <= 1 << (n - i + 1); j += 2)
if(a[j] > a[j + 1])
b[++ cnt] = a[j];
else
b[++ cnt] = a[j + 1];
for(int j = 1; j <= cnt; j ++)
a[j] = b[j];
}
int t;
if(a[1] < a[2]) t = a[1];
else t = a[2];
for(int i = 1; i <= m; i ++)
if(t == id[i])
{
printf("%d\n", i);
return 0;
}
}
M.玩游戏
#include <stdio.h>
char s[4][110];
// int s[4][100];
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
int n;
scanf("%d", &n);
for(int i = 1; i <= 2; i ++)
scanf("%s", s[i] + 1);
int k = 0;
for(int i = 1; i <= n; i ++)
{
if(s[1][i] == s[2][i] && s[1][i] == '1')
k = 1;
}
if(k == 1) puts("NO");
else puts("YES");
}
return 0;
}
标签:main,return,int,代码,新生,考核,ans,include,scanf
From: https://www.cnblogs.com/Chesedss/p/16890714.html