zoukankan      html  css  js  c++  java
  • 2016年海淀区中小学生信息学奥林匹克竞赛解题

    1.价钱统计:

    正确代码:

    #include <iostream>
    
    using namespace std;
    int main( )
    {
        float wm, p, g, a;
        float wm_price, p_price, g_price, a_price;
        float total_price = 0;
        cin>>wm>>p>>g>>a;
        wm_price = (int(wm*1.2*10+0.5)/10.0);
        p_price = (int(p*3.5*10+0.5)/10.0);
        g_price = (int(g*4.5*10+0.5)/10.0);
        a_price = (int(a*5*10+0.5))/10.0;
        total_price =(wm_price + p_price + g_price + a_price); 
        cout<<wm_price<<endl;
        cout<<p_price<<endl;
        cout<<g_price<<endl;
        cout<<a_price<<endl;
        cout<<total_price;
        //system("PAUSE");
        return 0;
    }

    2.打印图形:


    正确代码:

    #include <iostream>
    
    using namespace std;
    
    void print(int n)//空格函数:建议背下来! 
    {
        for(int x=0; x<n; x++)
            cout<<" "; 
    }
    int main()
    {
        int i, j, k, l;
        char zimu;
        cin>>zimu;
        for(i=0; i<int(zimu)-64; i++)
        {
            print(i);
            for(j=i; j<int(zimu)-64; j++)
                cout<<char(int(zimu)-j);    
                
            for(k=int(zimu)-64-1; k>=i+1; k--)
                cout<<char(int(zimu)-k);
            cout<<endl;            
        }
    } 

    3.数列计算:

    正确代码:

    #include <iostream>
    
    using namespace std;
    int main( )
    {
        float fenzi[31]={3,4,7};
        float fenmu[31]={4,7,11};
        int n; 
        float sum = 0;
        cin>>n;
        
        for(int i=2; i<=n; i++)
        {
            fenzi[i+1]=fenzi[i-1]+fenzi[i];
            fenmu[i+1]=fenmu[i-1]+fenmu[i];     
        }
        
        cout<<fenzi[n]<<"/"<<fenmu[n]<<endl;
        
        for(int i=1; i<=n; i++)
            sum =sum + (fenzi[i]/fenmu[i]);    
            
        cout<<int((sum)*100+0.5)/100.0;
        return 0;
    }
    #include<stdio.h>
    int main()
    {
    	int n,i,f[31];
    	double s=0.00;
    	scanf("%d",&n);
    	f[0]=4;
    	f[1]=7;
    	for(i=1;i<=n;i++)
    	{
    		s+=double(double(f[i-1])/double(f[i]));
    		f[i+1]=f[i]+f[i-1];
    	}
    	printf("%d/%d
    %.2f",f[n-1],f[n],s);
    }
    

    4.单词排序:

    正确代码:

    /*
    C++ vector用法:
    http://www.cnblogs.com/wang7/archive/2012/04/27/2474138.html
    */
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <vector>
    
    using namespace std;
    
    int main( ) 
    {    
        int n;    
        cin>>n;    
        vector<string> s(n);    
        for (int i=0; i<n; i++) 
            cin>>s[i];    
        sort(s.begin(), s.end());    
        for (int i=0; i<n; i++) 
            cout<<s[i]<<" ";       
        return 0;
    }
    
    /*
    
    input:
    5
    apple duty sense mom dark
    
    output:
    apple dark duty mom sense
     
    */

    5.评奖:

    #include "stdio.h"
    #include "stdlib.h"
    //#include "algorithm.h"
    
    struct stu
    {
        char name[20]; 
        int math;
        int Chinese;
        int English;
        int Geography;
        int sum;
    }; 
    
    int main( )
    {
         struct stu a[1000],temp;
         int n,i,j;
         scanf("%d",&n);
         
         for(i=0;i<n;i++)
         {
             scanf("%s%d%d%d%d",&a[i].name,&a[i].math,
                 &a[i].Chinese,&a[i].English,&a[i].Geography);
               a[i].sum = a[i].math + a[i].Chinese + 
                  a[i].English + a[i].Geography;
        }
                                  
         for(i=0;i<n;i++)
         {
             for(j=0;j<n-1;j++)
             {
                 if(a[j+1].sum>a[j].sum)
                {
                     temp=a[j];
                     a[j]=a[j+1];
                     a[j+1]=temp;
                 }
             }
         }
         
         for(i=0;i<3;i++)
             printf("%s
    ",a[i].name);
         return 0;
    }
    
    /*
    Input输入:
    4
    jing 98  90  87  74
    ming 96  92  85  97
    jun 95  78  56  91
    hong 95  100  85  78
    
    Output输出: 
    ming
    hong
    jing
    */

    6.附加字符串代码:

    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    int main( )
    {
        char a[1000], b[1000];
        cin>>a;    
        int len=strlen(a);
        cout<<len<<endl;
        for(int i=0;i<len;i++)
        {
            if(a[i]>='0' && a[i]<='9')
            {
                cout<<i+1<<endl;
                break;
            }
            else
            {
                cout<<"no"<<endl;
            }
        }
        strupr(a);
        cout<<a<<endl;
        return 0;
    }
  • 相关阅读:
    react fake double , bind click and dblclick on the same element
    Microbit MicroPython 介绍
    树莓派Raspberry Pi微改款,Model B 3+规格探析
    用Micro:bit做剪刀、石头、布游戏
    用Micro:bit做交通信号灯
    树莓派 Raspberry Pi 与 micro:bit起手式
    Microbit蓝芽配对
    micro:bit 软件生态系统介绍
    Micro:bit 硬件架构介绍
    Ruby 学习笔记7
  • 原文地址:https://www.cnblogs.com/6666junyiliu/p/6063156.html
Copyright © 2011-2022 走看看