2013年江西理工大學C語言程式設計競賽(初級組)

來源:互聯網
上載者:User

標籤:str   out   math   class   字串   找規律   getch   using   理工大學   

ACM ICPC WORLD FINAL

解法:排序大家都知道,去重的話,初學者用數組就好了

#include<algorithm>#include<iostream>using namespace std;int main(){    int a,b,c[100],i,d[31];    cin>>a;    while(a>0)    {        cin>>b;        for(i=0;i<31;i++)            d[i]=0;        for(i=0;i<b;i++)        {            cin>>c[i];        }         for(i=0;i<b;i++)         {             d[c[i]]++;         }         for(i=0;i<31;i++)         {             if(d[i]!=0)                cout<<i<<" ";         }         cout<<endl;         a--;    }} 

解法:找規律,前面的n行都是在中間輸出*,第n+1行全部輸出*,接下來的以中間為對稱關係,往兩邊擴充

#include <bits/stdc++.h>using namespace std;int main(){    int n;    while(cin>>n&&n)    {        for(int i=1;i<=2*n+1;i++)        {            for(int j=1;j<=2*n+1;j++)            {                if(j==n+1)                {                    cout<<"*";                }                else if(i==n+1)                {                    cout<<"*";                }                else if(i>n+1)                {                    int pos=i-(n+1);                    //cout<<pos<<endl;                    if(n+1-pos==j||n+1+pos==j)                    {                        cout<<"*";                    }                    else                    {                        cout<<".";                    }                }                else                {                    cout<<".";                }            }            cout<<endl;        }    }    return 0;}
我們都是江理人

解法:字串處理(根據題意)

#include<stdio.h>int main(){    int n,t,i;    char a[1000];    scanf("%d",&n);    getchar();    while(n--)    {        i=0;              gets(a);        for(t=0;a[t]!=‘\0‘;t++)        {            if(a[t]==‘1‘)             printf("love jiangli\n");            if(a[t]==‘2‘)            printf("love xingong\n");        }    }    return 0;}
迴文素數

解法:資料不大,當然是先判斷是不是迴文再判斷素數,(這裡可以把數字一位一位分解倒著相加看是否相等)

 

#include<stdio.h> int main() {     int m,n,c,b,k,p,q,r;     while(scanf("%d%d",&m,&n)!=EOF)     {         if(m==0&&n==0)             break;         r=0;         for(k=m; k>=m&&k<=n; k++)         {             b=0;             p=k;             while(k>0)             {                 c=k%10;                 b=b*10+c;                 k=k/10;             }             if(b==p)             {                 for(q=2; q<p; q++)                     if(p%q==0)                         break;                 if(q==p)                 {                     r=r+1;                 }             }             k=p;         }         printf("%d\n",r);     } }  
 獸獸扔鉛球

解法:數學題,沒什麼好說的

#include <stdio.h>#include<math.h>int main(){    int n;    float h,a,l;    while(scanf("%d",&n)!=EOF)    {        while(n--)        {            scanf("%f%f",&h,&a);            l=h/tan(a);            printf("%.3f\n",l);        }    }    return 0;}  
魔獸爭霸

解法:應該是計算斜率了(y2-y1)*(x3-x1)==(y3-y1)*(x2-x1)

#include<stdio.h>int main(){    double x1,x2,x3,y1,y2,y3;    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=0;i<n;i++)        {            scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);            if((y2-y1)*(x3-x1)==(y3-y1)*(x2-x1)&&(x2-x1)*(x2-x1)>=(x3-x1)*(x3-x1)&&(y2-y1)*(y2-y1)>=(y3-y1)*(y3-y1))            printf("yes\n");            else printf("no\n");        }    }    return 0;}

  

2013年江西理工大學C語言程式設計競賽(初級組)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.