diff --git a/cpp/algorithms/problem1.cpp b/cpp/algorithms/problem1.cpp index e69de29..e9cfdb5 100644 --- a/cpp/algorithms/problem1.cpp +++ b/cpp/algorithms/problem1.cpp @@ -0,0 +1,23 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2000 +#include + +void sort_and_output(char * str){ + for(int i=0;i<3;i++){ + for(int j=i+1;j<3;j++){ + if(str[i]>str[j]){ + char tmp=str[j]; + str[j]=str[i]; + str[i]=tmp; + } + } + } + printf("%c %c %c\n",str[0],str[1],str[2]); +} + +int main(int argc,char ** argv){ + char str[3]; + while(scanf("%s",str)!=EOF){ + sort_and_output(str); + } + return 0; +} \ No newline at end of file diff --git a/cpp/algorithms/problem2.cpp b/cpp/algorithms/problem2.cpp new file mode 100644 index 0000000..b8c123c --- /dev/null +++ b/cpp/algorithms/problem2.cpp @@ -0,0 +1,11 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2001 +#include +#include + +int main(int argc,char ** argv){ + double x1,y1,x2,y2; + while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF){ + printf("%.2f\n",sqrt(pow(x1-x2,2)+pow(y1-y2,2))); + } + return 0; +} \ No newline at end of file diff --git a/cpp/algorithms/problem3.cpp b/cpp/algorithms/problem3.cpp new file mode 100644 index 0000000..c021742 --- /dev/null +++ b/cpp/algorithms/problem3.cpp @@ -0,0 +1,11 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2002 +#include +#define PI 3.1415927 + +int main(int argc,char ** argv){ + double r; + while(scanf("%lf",&r)!=EOF){ + printf("%.3f\n",4.0/3.0*r*r*r*PI); + } + return 0; +} \ No newline at end of file diff --git a/cpp/algorithms/problem4.cpp b/cpp/algorithms/problem4.cpp new file mode 100644 index 0000000..858ba26 --- /dev/null +++ b/cpp/algorithms/problem4.cpp @@ -0,0 +1,10 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2003 +#include + +int main(int argc,char ** argv){ + double x; + while(scanf("%lf",&x)!=EOF){ + printf("%.2f\n",x>0?x:-x); + } + return 0; +} \ No newline at end of file