• 杭电oj平台上的11页题目代码:hdu-page11(2010-2019)


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

    int flower(int a)
    {
    int sum;
    int temp;
    temp = a;
    sum = 0;
    while (a)
    {
    sum = sum + (a % 10)*(a % 10)*(a % 10);
    a /= 10;
    }
    if (temp==sum)
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    int main()
    {
    int m, n;
    int count1 = 0;//记录非水仙花数
    int count2 = 0;//记录水仙花数
    while (~scanf("%d%d",&m,&n))
    {
    count1 = 0;
    count2 = 0;
    for (int i = m; i <= n; i++)
    {
    if (!flower(i))
    {
    count1++;
    }
    else
    {
    count2++;
    if (count2==1)
    {
    printf("%d", i);
    }
    else
    {
    printf(" %d", i);
    }
    }

    }
    if (count1==(n-m+1))
    {
    printf("no");
    }
    printf(" ");
    }
    return 0;
    }

    //2011
    #include<stdio.h>
    #include<math.h>
    int main()
    {
    int m;
    int i;
    int n;
    int j;
    double sum ;
    while (~scanf("%d",&m))
    {
    for (i = 1; i <= m; i++)
    {
    sum = 0;
    scanf("%d", &n);
    for ( j = 1; j <= n; j++)
    {
    if (j%2==1)
    {
    sum = sum + (1.0 / j);
    }
    else
    {
    sum = sum - (1.0 / j);
    }
    }
    printf("%.2lf ", sum);
    }
    }
    return 0;
    }


    //2012
    #include<stdio.h>
    #include<math.h>
    int isPrime(int a)
    {
    int i;
    //是从i=2开始,原来写成是1开始了,就wa了
    for (i = 2; i <= sqrt(double(a)); i++)
    {
    if (a%i==0)
    {
    break;
    }
    }
    if (i>sqrt(double(a)))
    {
    return 1;
    }
    return 0;
    }
    int main()
    {
    int x, y;
    int result;
    int i;
    int count;
    while (~scanf("%d%d",&x,&y))
    {
    if (x==0&&y==0)
    {
    break;
    }
    result = 0;
    count = 0;
    //for ( i = x+1; i < y; i++)
    //按照题目的输入和输出,输出的是OK,如果是(0,1)范围内的话是没有整数的,何来对应的素数,所以题目应该理解为[0,1]->[x,y]
    for (i = x; i <= y; i++)
    {
    result = i*i + i + 41;
    if (isPrime(result))
    {
    count++;//记录使表达式的值为素数的数的个数
    }
    }
    //if (count==(y-x-1))
    if (count==(y-x+1))
    {
    printf("OK ");

    }
    else
    {
    printf("Sorry ");
    }
    }
    return 0;
    }

    //2013
    //思路:设第n天剩下f(n),第n-1天剩下f(n-1),则f(n)= [f(n-1)-(f(n-1)/2+1)],整理得f(n-1)=2*[f(n)+1];但是已知的是第n天剩下的个数,所以应该从后往前推。
    //即:第n天是1;第n-1天是2(1+1);第n-2天是2(1+4);第n-3天是2(1+10);...则第一天是2(1+x)[x代表第二天的]
    #include<stdio.h>
    #include<math.h>
    int main()
    {
    int n;
    int i;
    int sum;
    while (~scanf("%d",&n))
    {
    sum = 1;
    for (i = 1; i < n; i++)
    {
    sum = 2*(1 + sum);
    }
    printf("%d ", sum);
    }
    return 0;
    }

    //2014
    #include<iostream>
    #include<algorithm>
    #include<iomanip>
    #define N 101
    double score[N];
    using namespace std;
    int main()
    {
    int i;
    int n;
    double average;
    double sum;
    while (cin>>n)
    {
    average = 0;
    sum = 0;
    for ( i = 0; i < n; i++)
    {
    cin >> score[i];
    }
    sort(score, score + n);
    for ( i = 1; i < n-1; i++)
    {
    sum += score[i];
    }
    average = sum / (n - 2);
    //保留两位小数
    cout << fixed<< setprecision(2)<< average << endl;
    }
    return 0;
    }

    //2015
    #include<iostream>
    #include<algorithm>
    #include<iomanip>
    #define N 101
    int num[N];
    using namespace std;
    int main()
    {
    int n, m;
    int j;
    int i;
    num[0] = 0;
    int average;
    int sum;
    int cnt1;
    int cnt2;//用来记录平均数的个数
    for (i = 1; i <= 100; i++)
    {
    num[i] = i * 2;
    }
    while (cin>>n>>m)
    {
    average = 0;
    sum = 0;
    cnt1 = 0;
    for (i = 1; i <= n; i++)
    {
    //average = 0;
    sum += num[i];
    cnt1++;//用来记录是否是达到m
    /*if (cnt2)
    {
    cout<<
    }*/

    if (cnt1==m&&i!=n)
    {
    cout << sum / cnt1<<' ';
    cnt1 = 0;
    sum = 0;
    }
    /*for ( j = i; j < i + m,j<=n; j++)
    {
    sum = sum + num[j];
    }
    average = 1.0*sum / m;
    if (i==1)
    {
    cout << average;
    }
    else
    {
    cout << ' ' << average;
    }*/

    }
    if (i==n+1)
    {
    cout <<sum/(cnt1)<< endl;
    }

    }
    return 0;
    }

    //2016
    #include<iostream>
    #include<algorithm>
    #include<iomanip>
    #define N 101
    int num[N];
    using namespace std;
    int main()
    {
    int n;
    int i;
    int min;
    int min_pos;
    int temp;
    while (cin>>n)
    {
    if (n==0)
    {
    break;
    }
    cin >> num[0];
    min = num[0];
    min_pos = 0;
    for ( i = 1; i < n; i++)
    {
    cin >> num[i];
    if (min>num[i])
    {
    min = num[i];
    min_pos = i;
    }
    }
    //交换最小数和第一个数
    temp = num[min_pos];
    num[min_pos] = num[0];
    num[0] = temp;
    for ( i = 0; i < n; i++)
    {
    if (i == 0)
    cout << num[i];
    else
    {
    cout << ' ' << num[i];
    }
    }
    cout << endl;
    }
    return 0;
    }

    //2017
    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<iomanip>
    #include<string.h>
    #define N 101
    char num[N];
    using namespace std;
    int main()
    {
    int n;
    int count;
    //int len;
    int i;
    while (~scanf("%d",&n))
    {
    while (n--)
    {
    count = 0;//记录数字的个数
    //gets(num);
    scanf("%s", num);
    for (i = 0; i < strlen(num);i++)
    if (num[i]>='0'&&num[i]<='9')
    {
    count++;
    }
    //cout << count << endl;
    printf("%d ", count);
    }
    }
    return 0;
    }

    //2019
    //思路:关键是找到插入的位置
    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<iomanip>
    #include<string.h>
    #define N 101
    int num[N];
    using namespace std;
    int main()
    {
    int n;
    int m;
    int i;
    int pos;//插入的位置
    while (cin>>n>>m)
    {
    if (n==0&&m==0)
    {
    break;
    }
    pos = 0;
    for ( i = 0; i < n; i++)
    {
    cin >> num[i];
    }
    for ( i = 1; i < n; i++)
    {
    //if (m>num[i - 1] && m < num[i])
    if (m<num[i])
    {
    pos = i;//插入在下标为i-1后面
    break;
    }
    }
    //网上的想法:直接打印前部分的,接着打印m,最后打印后部分的
    for ( i = 0; i < pos; i++)
    {
    cout << num[i] << ' ';
    }
    cout << m;
    for ( i = pos; i < n; i++)
    {
    cout << ' ' << num[i];
    }
    //我的想法:因为m要插入到数组中,所以后面的要向后移动一个
    /*for ( i = n-1; i >= pos+1; i--)
    {
    num[i+1] = num[i];
    }
    num[pos + 1] = m;
    cout << num[0];
    for ( i = 1; i < n+1; i++)
    {
    cout << ' ' << num[i];
    }*/
    cout << endl;
    }
    return 0;
    }

    一生有所追!
  • 相关阅读:
    Linux Process Memory Usage
    ezwinports
    Linux程序调试查看二进制文件
    Build tcpdump for ARM
    Tomcat start/stop script
    Apache+PHP+MySQL
    查看安装的glibc版本
    CodeMirror
    GeSHi Generic Syntax Highlighter
    C++命令行解析库
  • 原文地址:https://www.cnblogs.com/BlueBlue-Sky/p/8563940.html
Copyright © 2020-2023  润新知