P5722 [深基4.例11] 数列求和
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int sum = 0;
for (int i = 1; i <= n; i++) sum += i;
printf("%d\n", sum);
return 0;
}
P5718 [深基4.例2] 找最小值
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int mn = 1000;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
if (x < mn) mn = x;
}
printf("%d\n", mn);
return 0;
}
P5724 [深基4.习5] 求极差 / 最大跨度值
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int mx = 0, mn = 1000;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
mx = max(mx, x);
mn = min(mn, x);
}
printf("%d\n", mx - mn);
return 0;
}
P1085 [NOIP2004 普及组] 不高兴的津津
#include <cstdio>
int main()
{
int unhappy = 0;
int day = 0;
for (int i = 1; i <= 7; i++) {
int a, b;
scanf("%d%d", &a, &b);
if (a + b > 8 && a + b > unhappy) {
unhappy = a + b;
day = i;
}
}
printf("%d\n", day);
return 0;
}
P5719 [深基4.例3] 分类平均
#include <cstdio>
int main()
{
int n, k;
scanf("%d%d", &n, &k);
int sum1 = 0, cnt1 = 0;
int sum2 = 0, cnt2 = 0;
for (int i = 1; i <= n; ++i) {
if (i % k == 0) {
sum1 += i;
++cnt1;
} else {
sum2 += i;
++cnt2;
}
}
printf("%.1f %.1f\n", sum1 * 1.0 / cnt1, sum2 * 1.0 / cnt2);
return 0;
}
P1075 [NOIP2012 普及组] 质因数分解
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
for (int i = 2; i * i <= n; ++i)
if (n % i == 0) {
printf("%d\n", n / i);
break;
}
return 0;
}
P5720 [深基4.例4] 一尺之棰
#include <cstdio>
int main()
{
int a;
scanf("%d", &a);
int cur = 1;
while (a > 1) {
a /= 2;
++cur;
}
printf("%d\n", cur);
return 0;
}
P1035 [NOIP2002 普及组] 级数求和
#include <cstdio>
int main()
{
int k;
scanf("%d", &k);
double s = 0;
int n = 0;
while (s <= k) {
n++;
s += 1.0 / n;
}
printf("%d\n", n);
return 0;
}
P2669 [NOIP2015 普及组] 金币
#include <cstdio>
int main()
{
int k;
scanf("%d", &k);
int sum = 0;
int coin = 1;
int day = 0;
for (int i = 1; i <= k; i++) {
sum += coin;
day++;
if (day == coin) {
coin++;
day = 0;
}
}
printf("%d\n", sum);
return 0;
}
P1307 [NOIP2011 普及组] 数字反转
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
if (n < 0) {
printf("-");
n = -n;
}
int ans = 0;
while (n > 0) {
ans = ans * 10 + n % 10;
n /= 10;
}
printf("%d\n", ans);
return 0;
}
P5721 [深基4.例6] 数字直角三角形
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int num = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i + 1; j++) {
num++;
printf("%02d", num);
}
printf("\n");
}
return 0;
}
P5725 [深基4.习8] 求三角形
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int num = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
num++;
printf("%02d", num);
}
printf("\n");
}
printf("\n");
num = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) printf(" ");
for (int j = 1; j <= i; j++) {
num++;
printf("%02d", num);
}
printf("\n");
}
}
P1980 [NOIP2013 普及组] 计数问题
#include <cstdio>
int main()
{
int n, x;
scanf("%d%d", &n, &x);
int ans = 0;
for (int i = 1; i <= n; i++) {
int t = i;
while (t > 0) {
if (t % 10 == x) ans++;
t /= 10;
}
}
printf("%d\n", ans);
return 0;
}
P4956 [COCI2017-2018#6] Davor
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
n = n / 52 / 7;
for (int x = 100; x >= 1; x--) {
if ((n - x) % 3 == 0) {
int k = (n - x) / 3;
if (k > 0) {
printf("%d\n%d\n", x, k);
break;
}
}
}
return 0;
}
P1888 三角函数
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
int big = max(a, max(b, c));
int small = min(a, min(b, c));
int x = big, y = small;
while (y != 0) {
int t = x;
x = y;
y = t % y;
}
big /= x;
small /= x;
printf("%d/%d\n", small, big);
return 0;
}
P1420 最长连号
#include <cstdio>
int main()
{
int n;
scanf("%d", &n);
int pre = -1, ans = 1, len = 1;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
if (pre + 1 == x) {
len++;
if (len > ans) ans = len;
} else {
len = 1;
}
pre = x;
}
printf("%d\n", ans);
return 0;
}
P5726 [深基4.例9] 打分
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int sum = 0;
int mx = 0;
int mn = 10;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
sum += x;
mx = max(mx, x);
mn = min(mn, x);
}
printf("%.2f\n", 1.0 * (sum - mx - mn) / (n - 2));
return 0;
}
标签:mn,main,参考,int,代码,1.3,printf,include,scanf
From: https://www.cnblogs.com/ronchen/p/17576970.html