请教两个简单的C++编程问题
1、#include <iostream> using namespace std; int main(){ char c[100]; cin>>c; cout<<"length of the number is "<<strlen(c)<<endl; for(int i=0;i<strlen(c);i++){ cout<<"the "<<i+1<<"th number is "<<c[i]<<endl; } for(int i=strlen(c)-1;i>=0;i--) cout<<c[i]; cou
t<<endl; return 0; } 2、#include <iostream> using namespace std; int main(){ int i,j,s[5]; cout<<"清输入4个整数:"<<endl;for(i=0;i<4;i++)cin>>s[i]; for(i=0;i<4;i++) for(j=0;j<4-i-1;j++) if(s[j+1]<s[j]){ s[4] = s[j]; s[j] = s[j+1]; s[j+1] = s[4]; } for(i=0;i<4;i++) cout<<s[i]<<" "; cout<<endl; return 0;} 3、#include <iostream> using namespace std; int main() { int a,b,c;for(a='X';a<='Z';a++)for(b='X';b<='Z';b++)for(c='X';c<='Z';c++){if(a==b || b==c || a==c){continue; }if(a=='X' || c=='X' || c=='Z'){continue; }printf("\nOne solution is:\n");printf("A-%c\n",a);printf("B-%c\n",b);printf("C-%c\n",c);}return 0;}。
。
[展开]
/* * tp。
cpp * * Created on: 2008-11-15 * Author: T */A1:#include <iostream>using namespace std;int main(){ char c[100]; cin>>c; cout<<"length of the number is "<<strlen(c)<<endl; for(int i=strlen(c)-1;0<=i;i--){ cout<<"the "<<strlen(c)-i<<
"th number is "<<c[i]<<endl; } for(int i=strlen(c)-1;0<=i;i--) cout<<c[i]; cout<<endl; return 0;}A2:#include <iostream>using namespace std;int main(){ int i,j,s[5]; for(i=0;i<4;i++)cin>>s[i]; for(i=0;i<4;i++) for(j=0;j<4-i-1;j++) if(s[j+1]<s[j]){ s[4] = s[j]; s[j] = s[j+1]; s[j+1] = s[4]; } for(i=0;i<4;i++) cout<<s[i]<<" "; cout<<endl;}A3:怎么能办到?同校不比赛?这可能么,3个人肯定要分开,分开就一定要比赛阿我按照另外一个意思理解,同组的比赛?#include <iostream>using namespace std;int main(){ int a,b,c,x,y,z; bool t = true; for(a=1;a<=3&&t;a++) for(b=1;b<=3&&t;b++) for(c=1;c<=3&&t;c++) for(x=1;x<=3&&t;x++) for(y=1;y<=3&&t;y++) for(z=1;z<=3&&t;z++) if(a!=b && a!=c && b!=c && x!=y && x!=z && y!=z && a!=x && c!=x && c!=z){ cout<<"A: "<<a<<" ,B: "<<b<<" ,C: "<<c<<" ,X: "<<x<<" ,Y: "<<y<<" ,Z: "<<z<<endl; t = false; } return 0;}answer:A: 1 ,B: 2 ,C: 3 ,X: 2 ,Y: 3 ,Z: 1AZ一组 BX一组 CY一组。
[展开]
//三道题均测试通过//第一题#include<iostream>using namespace std;int main(){ int n,a[5]={0}; cout<<"Please input the number: "; cin>>n; int m=n; int i=0; while(n>0) { a[i]=n%10; n=n/10; i++; } i=4; while(a[i]==0) { i--; } cout<<"一共有"<<i+1<<"位数"<<endl; for(int j=i;j>=0;j--) cout<<
;a[j]<<ends; cout<<endl; for(j=0;j<=i;j++) cout<<a[j]<<ends; cout<<endl; return 0;}//第二题#include<iostream>using namespace std;void change(int &a,int &b){ int temp; temp=a; a=b; b=temp;}int main(){ int a[4]; cout<<"请依次输入四个数: "<<endl; int i=0; for(i=0;i<4;i++) cin>>a[i]; for(int j=0;j<3;j++) { for(i=0;i<3;i++) { if(a[i]>a[i+1]) change(a[i],a[i+1]); } } for(i=0;i<4;i++) cout<<a[i]<<ends; cout<<endl; return 0;}//第三题#include <iostream> using namespace std; int main() { char a,b,c; for(a='X';a<='Z';a++) for(b='X';b<='Z';b++) for(c='X';c<='Z';c++) { if(a==b || b==c || a==c) { continue; } if(a=='X' || c=='X' || c=='Z') { continue; } cout<<"分组方法是:"<<endl;cout<<"A->"<<a<<endl;cout<<"B=>"<<b<<endl;cout<<"C->"<<c<<endl;} return 0; }。
。
[展开]
三,,main(){ char i,j; for(i=A;i++;i<=C) for(j=X;j++;j<=Z) { if(i==A&&j==X) continue; else if(i==A&&(j==X||j==Z)) continue; else cout<<i"-->"j<<endl; }}。