喵宅苑 MewoGarden × 技术宅社区II | Z站 Z Station 棒棒哒纯文字二次元技术社区

正文

[i=s] 本帖最后由 天堂at人间 于

作者:天堂at人间
[i=s] 本帖最后由 天堂at人间 于 2013-5-3 23:00 编辑 参与人ID(UID): 天堂at人间 (370621) 参与类型: A 编程题目类 答案: 1 #include<iostream> using namespace std; int main() { int a,i,j; for(a=2;a<=1000;a++){ j=0; for(i=1;i<a;i++){ if(a%i==0){j=j+i;} } if(a==j){cout<<a<<endl;} } return 0; } 2 #include<iostream> using namespace std; int main() { float sum=0,current,i,j; current=50; for(i=1;i<=(10-1);i++){ sum=sum+current*2; current=current/2; } sum=sum+100; cout<<"第10次落地时,共经过"<<sum<<endl; cout<<"第10次反弹多高?"<<current; return 0; } 3 #include <cstdio> #include <cstdlib> int main(int argc, char **argv) { int i,j; for(i='A';i<='C';i++) for(j='X';j<='Z';j++) if(!((i=='A'&&j=='X')||(i=='C'&&(j=='X'||j=='Z')))) printf("%c----%c\n",i,j); system("pause"); return 0; } 4 #include <cstdio> #include <cstdlib> int age(int n) { int c; if( n==1 ) c=10; else c=age(n-1)+2; return c; } int main(int argc, char **argv) { printf("%d \n",age(5)) ; system("pause"); return 0; } 5 #include <iostream> #include <cstdlib> #include <list> using namespace std; void my_sort(list<int> &l) { for(list<int>::iterator i = l.begin(); i != l.end(); ++i) for(list<int>::iterator j = i; j != l.end(); ++j) { if(i == j) continue; if(*i > *j){ int t = *i; *i = *j; *j = t; } } } int main(int argc, char *argv[]) { list<int> l; int t; cout << "输入数字,以-1结束:"; while(cin>>t, t!=-1){ l.push_back(t); } my_sort(l); for(list<int>::iterator iter = l.begin(); iter != l.end(); ++iter) { cout << *iter << " "; } system("pause"); return 0; } 6 #include <stdio.h> #include <cstdlib> void reverse(char *_str,int len) { char*p=_str,*q=_str+len-1; len/=2; while(len>0) { *p=*p^*q; *q=*p^*q; *p=*p^*q; p++; q--; len--; } } int main() { char str0[11]= "0123456789"; reverse(str0,sizeof(str0)-1); printf("str0 = %s\n",str0); char str1[6]="01234"; reverse(str1,sizeof(str1)-1); printf("str1 = %s",str1); system("pause"); return 0; } 7 #include <iostream> #include <cstdlib> using namespace std; int main(int argc, char **argv) { long i; float bonus,bon1,bon2,bon4,bon6,bon10; int c; bon1=100000*0.1; bon2=bon1+100000*0.075; bon4=bon2+200000*0.05; bon6=bon4+200000*0.03; bon10=bon6+400000*0.015; cout<<"请输入当月利润:"; cin>>i; c=i/100000; if (c>10) c=10; switch(c) { case 0: bonus=i*0.1; break; case 1: bonus=bon1+(i-100000)*0.075; break; case 2: case 3: bonus=bon2+(i-200000)*0.05;break; case 4: case 5: bonus=bon4+(i-400000)*0.03;break; case 6: case 7: case 8: case 9: bonus=bon6+(i-600000)*0.015; break; case 10: bonus=bon10+(i-1000000)*0.01; } cout<<"奖金为:"<<bonus<<endl; system("pause"); return 0; } 8 #include <cstdio> #include <cstdlib> int main(int argc, char **argv) { int day,x1,x2; day=9; x2=1; while(day>0) { x1=(x2+1)*2; x2=x1; day--; } printf("总桃子数为: %d\n",x1); system("pause"); return 0; } 9 #include<iostream> using namespace std; int main() { int t,compare,record,a[10]; cout<<"请输入10个数:"; for(int k=0;k<=9;k++) cin>>a[k]; compare=a[0]; for(k=0;k<=9;k++){ if(a[k]>compare){compare=a[k];record=k;} } t=a[0]; a[0]=a[record]; a[record]=t; for(k=0;k<=9;k++){ if(a[k]<compare){compare=a[k];record=k;} } t=a[9]; a[9]=a[record]; a[record]=t; for(k=0;k<=9;k++) cout<<a[k]<<" "; return 0; }

回复

0%
闽ICP备2022013136号闽公网安备35092202000188号
站点地图友情链接:
喵宅苑
喵空间社区程序
喵宅苑 静态版
宅喵RPG地图编辑器
络合兔
Lanzainc
技术宅
小五四博客
莉可POI
Mithril.js
枫の主题社
Project1
午后少年
机智库
七濑胡桃
xiuno
幻想の日常
魂研社
Nothentai
0xffff
欲望之花
泽泽社长
淀粉月刊
HAYOU