(HDU)1040 --As Easy As A+B(像A+B一样简单)

题目链接:http://vjudge.net/problem/HDU-1040

思路:排序算法的水题。注意输出格式,数字之间有空格。

 1     #include <iostream>
 2     #include <cstdio>
 3     #include <cstring>
 4     using namespace std;
 5
 6     int main()
 7     {
 8         int n,num,i,j,temp;
 9         int s[1010];
10         scanf("%d",&n);
11         while(n--)
12         {
13             scanf("%d",&num);
14             for(i=1;i<=num;i++)
15                 scanf("%d",&s[i]);
16             for(i=1;i<num;i++)
17                 for(j=i+1;j<=num;j++)
18             {
19                 if(s[i]>s[j])
20                 {
21                     temp=s[i];
22                     s[i]=s[j];
23                     s[j]=temp;
24                 }
25             }
26             for(i=1;i<num;i++)
27                 printf("%d ",s[i]);
28                 printf("%d\n",s[i]);
29         }
30         return 0;
31     }

  下面是直接用sort函数的方法(偷懒...)

 1     #include <iostream>
 2     #include <cstdio>
 3     #include <cstring>
 4     #include <algorithm>
 5     using namespace std;
 6
 7     int main()
 8     {
 9         int n,num,i;
10         int s[1010];
11         scanf("%d",&n);
12         while(n--)
13         {
14             scanf("%d",&num);
15             for(i=0;i<num;i++)
16                 scanf("%d",&s[i]);
17             sort(s,s+num);
18             for(i=0;i<num-1;i++)
19                 printf("%d ",s[i]);
20                 printf("%d\n",s[i]);
21         }
22         return 0;
23     }

时间: 2024-10-08 09:57:52

(HDU)1040 --As Easy As A+B(像A+B一样简单)的相关文章

hdu 1040 As Easy As A+B

As Easy As A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 53368    Accepted Submission(s): 22939 Problem Description These days, I am thinking about a question, how can I get a problem as

HDU 1040.As Easy As A+B【排序】【如题(水!水!水!)】【8月24】

As Easy As A+B Problem Description These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights. Give you some integers, your task is to s

杭电 HDU 1040 As Easy As A+B

As Easy As A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 43019    Accepted Submission(s): 18379 Problem Description These days, I am thinking about a question, how can I get a problem as

HDU 1040 As Easy As A+B (排序。。。水题)

题意:给定n个数,让你从小到大排序. 析:不说什么了. 代码如下: #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int maxn = 1000 + 5; int a[maxn]; int main(){ int T, n; cin >>

hdu 1040 As Easy As A+B(排序)

题意:裸排序 思路:排序 #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int a[1000]; int main(){ int t,n,i; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<n;++i) scanf("%d&quo

HDU 1040

As Easy As A+B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35088 Accepted Submission(s): 15142 Problem Description These days, I am thinking about a question, how can I get a problem as easy a

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=2 1.2.5 #include<stdio.h> /* 题意:找闰年. if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855 12 2004 10000 2108 1904 43236 */ int main() { int t,y,n; int i,count=0; whil

HDU 4565 So Easy!

线性推,矩阵乘法+快速幂求通项. 传送门:点击打开链接 #include <cstdio> #include <cstring> #include <cmath> #include <iostream> using namespace std; #define LL long long struct Mat{ LL f[2][2]; }; LL MOD; Mat mul(Mat a,Mat b) { LL i,j,k; Mat c; memset(c.f,0

HDU 5058 So easy (set容器大法好)

题目链接:HDU 5058 So easy 题意:给出两个序列,问这个两个序列构成的集合是否相同. set大法好! AC代码: #include<stdio.h> #include<set> #include<map> using namespace std; #define ll __int64 set<ll> ss1,ss2; set<ll>::iterator it; int main() { ll n,i; while(scanf(&qu

HDU 3623 Best Cow Line, Gold(模拟,注意思路,简单)

题目 POJ 3617 和 这道题题目一样,只是范围稍稍再小一点. //模拟试试 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; char s[30010][2]; bool bijiao(int st,int ed) { if(st==ed) return true; if(s[st][0]<s[ed][0]) return true; else if(s