SDNUOJ 小部分题解
当时写的如 ** 一般,现在整理,一点一点规范…
1010
#include<stdio.h>
int main()
{
int n, i, space, line, star;
scanf("%d", &n);
for(line = 1; line < 2 * n; line++)
{
if(line <= n)
space = n - line;
else
space = line - n;
star = n - space;
for(i = 0; i < space; i++)
printf(" ");
for(i = 0; i < 2 * star - 1; i++)
printf("*");
printf("\n");
}
return 0;
}
1013
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
bool compare(int a,int b)
{
return a>b;
}
int main()
{
int n;
cin >> n;
int a[10004];
for(int i = 0;i < n;i++)
cin >> a[i];
sort(a, a + n, compare);
long long sum = 0;
int b[10004];
b[0] = a[0];
for(int i = 1; i < n; i++)
{
b[i] = b[i-1] + a[i];
sum += b[i];
}
int d;
d = sum % 1000000007;
cout << d;
return 0;
}
1014
#include<cstdio>
#include<iostream>
using namespace std;
int page(int n,int x)
{
int sum = 0, a, k;
for(int i = 1;( k = n / i) != 0;i *= 10)
{
int divide = (k / 10);
if(x == 0)
divide--;
sum += divide * i;
int yushu = k % 10;
if(yushu > x)
sum += i;
else if(yushu == x)
sum += n - k * i + 1;
}
return sum;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d %d %d %d %d %d %d %d %d %d",page(n, 0), page(n, 1), page(n, 2), page(n, 3), page(n, 4), page(n, 5), page(n, 6), page(n, 7), page(n, 8), page(n, 9));
return 0;
}
1017
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
long long n, a[2000];
while(scanf("%lld",&n) != EOF)
{
for(int i = 0; i < n; i++)
{
scanf("%lld", &a[i]);
}
sort(a, a + n);
for(int i = 0; i < n; i++)
{
printf("%lld", a[i]);
printf(" ");
}
printf("\n");
}
return 0;
}
1018
#include<stdio.h>
int main()
{
char a[9999];
int b = 0;
int c = 0;
int d = 0;
scanf("%s", a);
for(int i = 0; i < 10000; i++)
{
if(a[i] == 'W')
b++;
else
c++;
if(b == 3)
{
d = d + 1;
b = 0;
c = 0;
}
if(c == 3)
{
c = 0;
b = 0;
}
}
printf("%d",d);
return 0;
}
1020
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%c%d", &a, &b, &c);
if(b == '+')
printf("%d", a + c);
else if(b == '-')
printf("%d", a - c);
else if(b == '*')
printf("%d", a * c);
else if(b == '/')
printf("%d", a / c);
return 0;
}
1021
#include<stdio.h>
int main()
{
int n, z, l, a, b, c, d;
a = 1;
b = 1;
c = 0;
d = 0;
scanf("%d", &n);
scanf("%d%d", &z, &l);
for(; n >= a ;)
{
if(a % z == 0)
c = c + 1;
a++;
}
for(; n >= b;)
{
if(b % l == 0 && b % z != 0)
d = d + 1;
b++;
}
printf("%d %d", c, d);
return 0;
}