已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ACM那点事c+语言中怎么样保留float数小数点的后两位需要有这个!#include /第一种方式,从根本改变输出流 coutsetiosflags(ios:fixed)setprecision(2)aendl; coutsetiosflags(ios:fixed)setprecision(2)bendl; /第二种方式,简缩型 coutendl; coutsetprecision(2)fixedaendl; coutsetprecision(2)fixedbendl; /第三种方式,全局整体型这种方法是保留两个有效数字,而不是小数点后边两位 coutendl; cout.precision(2); coutaendl; coutbendl; return 0;字符与ascii码转换问题#includeusing namespace std;int main() char s=A; cout(int)sendl; int x=70; cout(char)xendl;1006 输入一串字符,判断有多少个重复的字符串例如:abcd 1 aaaa 4 ababab 3#include char s1000001;int next1000001;int main() int i,j,n,t; while(gets(s) & s0!=.) i=0; next0=-1; j=-1;l1:while(si!=0) if(j=-1 | si=sj) +i; +j; nexti=j; goto l1; j=nextj; n=i; t=n-nextn; if(n%t=0)printf(%dn,n/t); else printf(1n); return 0;1009 棋盘问题. X. X.O X.O X.O X.O X.O X.O. . . . .O. .O. OO. OO. . . .X .X X.X X.X XXX输入:2X.OOO.XXXO.XXX.OOO输出:yesno#include using namespace std;char s34;int num(char c) int i,j; int sum=0; for(i=0;i3;i+) for(j=0;j3;j+) if(sij=c)+sum; return sum; int line(char c) int i; for(i=0;in; for(;n0;n-) getchar(); gets(s0); gets(s1); gets(s2); a=num(X);b=num(O); if(ab) coutno1) coutnoendl; continue; if(a-b=1) if(line(O) coutnoendl; continue; if(a=b) if(line(X) coutnoendl; continue; coutyesendl; return 1; 1011 矩形小木块,落法,求最小表面积Sample Input59102627100Sample Output30348254130#include#includeusing namespace std;int main() int x; int area; int n; while(cinn & n!=0) while(n) cinx; int s=2+4*x; for(int i=1;i=x;i+) if(x%i=0) for(int j=1;j=x/i;j+) if(x/i%j=0) area=2*(i*j+i*x/i/j+j*x/i/j); if(areas) s=area; coutsendl; n-; 1016 一道有关欧拉函数5的问题DescriptionIt is said that 90% of frosh expect to be above average in their class. You are to provide a reality check.InputThe first line of standard input contains an integer C, the number of test cases. C data sets follow. Each data set begins with an integer, N, the number of people in the class (1 = N = 1000). N integers follow, separated by spaces or newlines, each giving the final grade (an integer between 0 and 100) of a student in the class.OutputFor each case you are to output a line giving the percentage of students whose grade is above average, rounded to 3 decimal places.Sample Input55 50 50 70 80 1007 100 95 90 80 70 60 503 70 90 803 70 90 819 100 99 98 97 96 95 94 93 91Sample Output40.000%57.143%33.333%66.667%55.556%#include #includeusing namespace std;int main() double a1000,sum,num; int t,n,i; float k; cint; for(;t0;t-) cinn; sum=0;num=0; for(i=0;iai; sum+=ai; sum/=n; for(i=0;isum) +num; k=100*num/n; coutsetprecision(3)fixedk%endl; return 0;1022 一场战争,持续n天。这个人的上下左右四个方向可以与之发生战争。其中R战胜S,s战胜p,p战胜r。战胜每天一总结,只输出最后的。Sample Input23 3 1RRRRSRRRR3 4 2RSPRSPRSPRSPSample OutputRRRRRRRRRRRRSRRSPRSPR#includeusing namespace std;int main() int l; cinl; while(l) int x,y,z; cinxyz; char a101101,b101101; for(int i=0;ix;i+) for(int j=0;jaij; bij=aij; while(z) for(int i=0;ix;i+) for(int j=0;jy;j+) if(aij=R) if(ai-1j=P | ai+1j=P | aij+1=P | aij-1=P) bij=P; if(aij=S) if(ai-1j=R | ai+1j=R | aij+1=R | aij-1=R) bij=R; if(aij=P) if(ai-1j=S | ai+1j=S | aij+1=S | aij-1=S) bij=S; for(int i=0;ix;i+) for(int j=0;jy;j+) aij=bij; z-; for(int i=0;ix;i+) for(int j=0;jy;j+) coutaij; cout1) coutendl; l-; 1027 猜数字,大了输出头too high,小了输出too low,到最后看看一开始顶数字的那个人有没有玩赖。Sample Input10too high3too low4too high2right on5too low7too high6right on0Sample OutputStan is dishonestStan may be honest#include#include#include using namespace std;int main() int x; int i; char bh30; string s; int n10; for(i=0;ix) cin.ignore(100, n); if(x=0) break; gets(bh); s=bh; if(s=too high) for(i=x-1;i10;i+) ni=0; if(s=too low) for(i=0;i=x-1;i+) ni=0; if(s=right on) for(i=0;i10;i+) if(nx-1=1) for(i=0;i10;i+) ni=1; coutStan may be honestendl; break; else coutStan is dishonestendl; for(i=0;i10;i+) ni=1; break; 1029 锁头转动度数的问题,规则如下:turn the dial clockwise 2 full turnsstop at the first number of the combinationturn the dial counter-clockwise 1 full turncontinue turning counter-clockwise until the 2nd number is reachedturn the dial clockwise again until the 3rd number is reachedpull the shank and the lock will open.Sample Input0 30 0 305 35 5 350 20 0 207 27 7 270 10 0 109 19 9 190 0 0 0Sample Output135013501620162018901890#includeusing namespace std;int main() int a,b,c,d; int sum; while(cinabcd & (a | b | c | d) sum=0; sum=1080+(40+(a-b)%40*9+(40+(c-b)%40*9+(40+(c-d)%40*9; coutsumendl; 1029another idea#include using namespace std;float lockemu(int s,int t,int d)int m40;for(int i=0;is1s2s3s4 & s1+s2+s3+s4!=0)cout720+lockemu(s1,s2,-1)+360+lockemu(s2,s3,1)+lockemu(s3,s4,-1)endl;return 0; 1029myself#includeusing namespace std;int main() int a,b,c,d; int sum1,sum2,sum3; int sum; while(cinabcd) sum1=sum2=sum3=0; sum=0; if(a!=0 | b!=0 | c!=0 | d!=0) if(ab) sum1=(a-b)*9; else sum1=360; if(bc) sum2=(40-(b-c)*9; else if(bc) sum2=(c-b)*9; else sum2=360; if(cd) sum3=(c-d)*9; else sum3=360; sum=1080+sum1+sum2+sum3; coutsumendl; else break; return 0;1039 求的问题#includeusing namespace std;int main() long long x,y,sum; while(cinxy) if(x=0 & y=0) break; int i,j; sum=1; if(xy*2) for( i=(x-y+1),j=1;i=x,j=y;i+,j+) sum=sum*i/j; if(x=y*2) for(i=y+1,j=1;i=x,j=(x-y);i+,j+) sum=sum*i/j; coutsum=2)得到的F(n)能被3整除,输出yes,反之输出no。Sample Input012345Sample Outputnonoyesnonono#includeusing namespace std;int main() int n; while(cinn) if(n=0) int a99999; a0=7; a1=11; int i; for(i=2;i=n;i+) ai=ai-1+ai-2; if(i2) coutnoendl; if(ai-1%3=0) coutyesendl; else coutnoendl; else continue; 1060 正明任何一个大于4的整数都可以分解成两个素数相加的和Sample Input820420Sample Output8 = 3 + 520 = 3 + 1742 = 5 + 37#include#includeusing namespace std;int main() int n,m,i,j,k,p; while(scanf(%d,&n)!=EOF) if(n%2!=0) continue; p=n/2; for(i=2;i=p;i+) k=0; for(j=2;j=(int)sqrt(i);j+) if(i%j=0) break; if(j=(int)sqrt(i)+1) m=n-i; for(k=2;k=(int)sqrt(m);k+) if(m%k=0) break; if(k=(int)sqrt(m)+1) /coutn = i + mendl; printf(%d = %d + %dn,n,i,m); break; if(i=p+1) printf(Goldbachs conjecture is wrong.); 1079 判断字符串包含问题Sample Inputsequence subsequenceperson compressionVERDI vivaVittorioEmanueleReDiItaliacaseDoesMatter CaseDoesMatterSample OutputYesNoYesNo#include#include#includeusing namespace std;int main() string s,s1; while(cins1s) int t=0,i=0,j=0; int length=0,length1=0; while(slength) length+; while(s1length1) length1+; while(si) if(s1j=si) j+; i+; if(j=length1) t=1; break; if(t=1) coutYesendl; else coutNoendl; 1082 求两个点(坐标形式)的终点问题Sample Input5 10 2 18 2 22 6 14 18 10 183 -4 6 -2 4 -2 63 -8 12 4 8 6 12Sample Output5 14.000000 2.000000 20.000000 4.000000 18.000000 12.000000 12.000000 18.00000010.000000 10.0000003 -3.000000 5.000000 -2.000000 5.000000 -3.000000 6.0000003 -2.000000 10.000000 5.000000 10.000000 -1.000000 12.000000#include#includeusing namespace std;int main() int n; while(cinn & n!=0) int i=0,s; double a99999,b99999; double c99999,d99999; s=n; while(s) cinaibi; i+; s-; for(int j=0;jn;j+) /cout; if(jn-1) cj=(aj+aj+1)/2.0; dj=(bj+bj+1)/2.0; if(j=n-1) cj=(aj+a0)/2.0; dj=(bj+b0)/2.0; coutn ; for(int j=0;jn;j+) coutsetprecision(6)fixedcj; cout ; coutsetprecision(6)fixeddj; if(j!=n-1) cout ; coutendl; 1198 限定一个最小的矩形,把输入的所有的点包含进去Sample Input12 5623 5613 100 012 340 00 0Sample Output12 10 23 5612 34 12 34#include#includeusing namespace std;int main() int x,y; int x1,y1,x2,y2; int i=1,j; while(i) x1=99999; y1=99999; y2=0; x2=0; j=0; while(cinxy & (x | y) j+; if(x1x) x1=x; if(x2y) y1=y; if(y2y) y2=y; if(j=0) break; coutx1 y1 x2 y2 42+1 - 43 - 34Sample Input324 14358 754305 794Sample Output3419981#include#include#includeusing namespace std;int main() int d; cind; while(d) int m,n,k; int i=0,j=0,g=0; int a100,b100,c100; int sum1=0,sum2=0; int x,y; cinmn; while(m) ai=m%10; m=m/10; i+; while(n) bj=n%10; n=n/10; j+; int length1,length2; length1=i-1; length2=j-1; for(int p=0;pi;p+) sum1+=ap*pow(10.0,(double)length1); length1-; for(int q=0;qj;q+) sum2+=bq*pow(10.0,(double)length2); length2-; int sum; sum=sum1+sum2; k=sum; while(k) cg=k%10; k=k/10; g+; int sum3=0,length3=g-1; for(int r=0;rg;r+) sum3+=cr*pow(10.0,(double)length3); length3-; coutsum3endl; d-; 1201 限定一个范围(二维坐标形式),然后输入n代表n组测试值(坐标),判断输入的点是否在限定的范围内,在输出0,不在输出-1.Sample Input10 0 5 534 15 16 10Sample Output00-1#include#includeusing namespace std;int main() int n; int i=0; int x1100,y1100,x2100,y2100; cinn; while(n) cinx1iy1ix2iy2i; i+; n-; int m; int x3,y3; int j=0,r; cinm; while(m) cinx3y3; for(r=i-1;r=0;r-) if(x3=x1r & y3=y1r) coutrendl; break; if(r=-1) coutrendl; m-; 1202 输
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年河南省永城市高一历史下册期末考试模拟考试卷附完整答案【历年真题】
- 2026年吉林省德惠市高三生物上册期末考试试卷及参考答案
- 济南市长清区2025届数学三年级第二学期期中学业质量监测模拟试题(含解析)
- 泸州市合江县2025年数学三年级第二学期期末调研模拟试题(含答案)
- 压电石英片烧银焊线工岗前技术知识考核试卷含答案
- 腐蚀控制工安全检查强化考核试卷含答案
- 印花配色打样工岗前安全生产规范考核试卷含答案
- 水生植物栽培工QC管理能力考核试卷含答案
- 雷达装调工安全文明知识考核试卷含答案
- 醋酸装置操作工安全理论水平考核试卷含答案
- 2026人工智能高质量数据集建设与应用实践白皮书
- T/CI 1408-2026城镇燃气安全检查与评价指南
- 中铝宁夏能源集团笔试题库
- 浙江省强基联盟2026-2027学年高二上学期开学化学试题含答案
- 2026年秋季开学大一晚自习规划学习方法指导课件
- DB34∕T 3079-2026 河道堤防减压井及测压管管理规程
- 2026统考专升本英语:作文模版20篇
- 2026年高考语文真题全国一卷文言文逐句注解+翻译(含课内拓展+文言现象)
- 2026年设计院工作总结(2篇)
- 2026年硫酸软骨素原料药行业分析报告及未来发展趋势报告
- 企业微信使用教程
评论
0/150
提交评论