Live2d Test Env

入门手把手教学代码

题目网站: http://acm.hdu.edu.cn/listproblem.php?vol=11

输入输出的对比:

    int x; char x;double x;cin>>x;
    int x; scanf("%d",&x); printf("%d\n",x);
    char c; scanf("%c",&c); printf("%c",c);
    double x; scanf("%lf",&x); printf("%lf",x);

 

HDU2000:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a,b,c;
    while(cin>>a>>b>>c){
       if(a>b) swap(a,b);
       if(b>c) swap(b,c);
       if(a>b) swap(a,b);
       cout<<a<<" "<<b<<" "<<c<<endl; 
    }
    return 0;
}
C语言版本:
#include<bits/stdc++.h> using namespace std; int main() { char a,b,c; while(~scanf("%c%c%c\n",&a,&b,&c)){ //过滤换行符 if(a>b) swap(a,b); if(b>c) swap(b,c); if(a>b) swap(a,b); printf("%c %c %c\n",a,b,c); } return 0; }

 

HDU2001:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double x1,x2,y,y2,ans;
    while(cin>>x1>>y>>x2>>y2){
        ans=sqrt((x1-x2)*(x1-x2)+(y-y2)*(y-y2));
        printf("%.2lf\n",ans);
    }
    return 0;
}

 

HDU1001:

 #include<bits/stdc++.h>
using namespace std;
int main()
{ 
    long long ans,n;
    while(cin>>n)
    {
        ans=(1+n)*n/2;
        cout<<ans<<endl;
        cout<<endl;
    }
    return 0;
}

HDU2002:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double r,pi=3.1415927; //int double
    while(cin>>r){
        printf("%.3lf\n",4.0/3*pi*r*r*r);
    }
    return 0;
}

 

HDU2003:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double N;
    while(cin>>N)
    {
        if(N>0) printf("%.2lf\n",N);
        else printf("%.2lf\n",-N);
    }
    return 0;
}

 HDU2010:

非函数版本
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int L,R;
    while(cin>>L>>R){
        int i,cnt=0;
        for(int i=L;i<=R;i++){
            int a=i/100;
            int b=(i-a*100)/10;
            int c=i%10;
            if(a*a*a+b*b*b+c*c*c==i){
                if(cnt==0) cout<<i;
                else cout<<" "<<i;
                cnt++;
            }
        }
        if(cnt==0) cout<<"no";
        cout<<endl;
    }
    return 0;
}

 

函数版本
#include<bits/stdc++.h> using namespace std; bool check(int x) { //356%10=6; 356/10=35; int a=x/100; int b=(x-a*100)/10; int c=x%10; if(pow(a,3)+pow(b,3)+pow(c,3)==x) return true; else return false; } int main() { int i,L,R; //3 4 5 6 while(cin>>L>>R){ int cnt=0; for(int i=L;i<=R;i++){ if(check(i)==true){ if(cnt==0) cout<<i; else cout<<" "<<i; cnt++; } } if(cnt==0) cout<<"no"; printf("\n"); } return 0; }

 2008:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N; double x;
    while(cin>>N){
       if(N==0) break;
       int a=0,b=0,c=0;
       for(int i=1;i<=N;i++){
           cin>>x;
           if(x<0) a++;
           else if(x==0) b++;
           else c++;
       }
       cout<<a<<" "<<b<<" "<<c<<endl;
    }
    return 0;
}

 

posted @ 2018-10-23 15:43  nimphy  阅读(3816)  评论(0编辑  收藏  举报