2013年江西理工大学C语言程序设计竞赛(初级组)
ACM ICPC WORLD FINAL
解法:排序大家都知道,去重的话,初学者用数组就好了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #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行全部输出*,接下来的以中间为对称关系,往两边扩展
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #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; } |
我们都是江理人
解法:字符串处理(根据题意)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #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; } |
回文素数
解法:数据不大,当然是先判断是不是回文再判断素数,(这里可以把数字一位一位分解倒着相加看是否相等)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #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); } } |
兽兽扔铅球
解法:数学题,没什么好说的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #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)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #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; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~