锘??xml version="1.0" encoding="utf-8" standalone="yes"?>#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
void Numtostring(int num,char s[]) //鑷畾涔夋暟瀛楄漿鎹㈡垚瀛楃涓插嚱鏁?nbsp;
{
int temp,i=0;
// char *s;
// s=(char *)malloc(500);
//char s[500];
while(num!=0)
{
temp=num%10;
s[i]=temp+48;
i++;
num=num/10;
}
s[i]='\0';
strrev(s);
}
int NumberTest0(int num) //鏁板瓧閫嗗簭錛岃繑鍥為嗗簭鍊?nbsp;
{
int temp;
int n,i;
int num0=0;
n=log10(num);
printf("n=%d\n",n);
for(i=n;i>=0;i--)
{
temp=num%10;
num=num/10;
num0+=temp*pow(10,i);
printf("num0=%d\n",num0);
}
return num0;
}
int StringTest(int num)//鍥炴枃鍒ゆ柇錛屽瓧絎︿覆閫嗚漿鎬濊礬
{
char s[500],s1[500];
Numtostring(num,s);//鏁板瓧杞崲鎴愬瓧絎︿覆鍑芥暟
puts(s);
strcpy(s1,s);
strrev(s1);
if(strcmp(s1,s)==0)
printf("Yes\n");
else
printf("No\n");
return 0;
}
int NumberTest1(int n)//鍥炴枃鍒ゆ柇 鑰佸笀瑙i鎬濊礬 鍚鏄ぇ紲炵駭鐨勪漢鐗╁啓鐨勩傘傘?/span>
{
int temp=0;
int m=n;
while(n)
{
temp=temp*10;
temp+=n%10;
n=n/10;
}
printf("%d\n",temp);
if(temp==m)
printf("Yes\n");
else
printf("No\n");
return 0;
}
int main()
{
int num,num0;
// long n;
char s[500];
while(scanf("%d",&num)!=EOF)
{
/**//*num0=Test(num);
printf("%d\n",num0);
if(num0==num)
printf("Yes\n");
else
printf("No\n");*/
// Numtostring(num,s);
// puts(s);
// StringTest(num);
NumberTest1(num);
}
return 0;
}
]]>#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
bool cmp(const int &a,const int &b)
{
return a>b;
}
int main()
{
vector<int> v1;
v1.push_back( 0 );
v1.push_back( 1 );
v1.push_back( 2 );
v1.push_back( 3 );
vector<int> v2;
v2.push_back( 5 );
v2.push_back( 6 );
v2.push_back( 7 );
v2.push_back( 8 );
cout << "Before, v2 is: ";
for( vector<int>::size_type i = 0; i < v2.size(); i++ )
{
cout << v2[i] << " ";
}
cout << endl;
/**//* cout << "Before, v2 is: ";
for( vector<int>::iterator iter =v2.begin() ; iter < v2.end(); iter++ ) {
cout << *iter << " ";
}
cout << endl;//榪唬鍣紝鐩稿綋浜庢寚閽堢殑姒傚康銆傘?/
// v2.insert( v2.end(), v1.begin(), v1.end() );//鍦╲2鏈熬鎻掑叆v1
// v2.insert(v2.end(),3,'3'); //鍦╲2鏈熬鎻掑叆3涓?1
// swap(v1,v2);
// v1.swap(v2); //浜ゆ崲
// printf("%d\n",v2.at(2)); // 杈撳嚭鎸囧畾浣嶇疆鍊?br>
// sort(v2.begin(),v2.end(),cmp); //鎺掑簭錛屼竴鐩存病寮勬槑鐧絚mp
// sort(v2.begin(),v2.end(),greater<int>()); //閫掑噺鎺掑簭
// sort(v2.begin(),v2.end(),less<int>()); //閫掑鎺掑簭
// v2.assign(v1.begin(),v1.end());//鎷瘋礉v1鍒皏2
// v2.erase(v2.end()-1,v2.end()); //鍒犻櫎瀹瑰櫒鍏冪礌錛屼笉鍖呮嫭絎竴涓暟
// v2.clear(); //娓呯┖
// v2.resize(2); //淇敼鍏冪礌涓暟
cout << "After, v2 is: ";
for( vector<int>::size_type j = 0; j < v2.size(); j++ )
{
cout << v2[j] << " ";
}
return 0;
}
]]>
COMPLEX.HPP鏂囦歡
#include<iostream.h>
class COMPLEX
{
public :
COMPLEX(double r=0,double i=0);
COMPLEX(const COMPLEX& other);
COMPLEX operator +(const COMPLEX& other);
COMPLEX operator -(const COMPLEX& other);
COMPLEX operator -();
COMPLEX operator =(const COMPLEX &other);
friend ostream& operator <<(ostream& stream,COMPLEX& obj);
friend istream& operator <<(istream& stream,COMPLEX& obj);
public :
double real,image;
};
//COMPLEX.CPP鏂囦歡
#include "COMPLEX.HPP" //灝嗗ご鏂囦歡鍖呮嫭榪涘幓,涓嶈兘鍐欐垚include<COMPLEX.CPP>銆傘傘?/span>
COMPLEX::COMPLEX(double r,double i)
{
real=r;
image=i;
return ;
}
COMPLEX::COMPLEX(const COMPLEX& other)
{
real=other.real;
image=other.image;
return ;
}
COMPLEX COMPLEX::operator +(const COMPLEX& other) //榪愮畻絎?閲嶈澆 鍙傛暟涓篊OMPLEX綾誨瀷錛岃繑鍥炲間負(fù)COMPLEX綾誨瀷鐨勫紩鐢紝涓嬪悓
{
COMPLEX temp;
temp.real=real+other.real;
temp.image=image+other.image;
return temp;
}
COMPLEX COMPLEX::operator -(const COMPLEX& other)
{
COMPLEX temp;
temp.real=real-other.real;
temp.image=image-other.image;
return temp;
}
COMPLEX COMPLEX::operator =(const COMPLEX& other)
{
real=other.real;
image=other.image;
return *this;
}
ostream& operator<<(ostream& stream,COMPLEX& obj) //嫻佹彁鍙栫閲嶈澆鏈変袱涓弬鏁幫紝絎竴涓弬鏁板嚭鐜板湪<<鎿嶄綔絎﹀乏渚э紝涓簅stream寮曠敤錛岀浜屼釜鍑虹幇鍦ㄦ搷浣滅<<鍙充晶錛屼負(fù)COMPLEX寮曠敤錛岃繑鍥炲兼槸涓涓猳stream鐨勫璞″紩鐢紝涓嬪悓
{
stream<<obj.real;
if(obj.image>0) stream<<"+"<<obj.image<<"i";
else if(obj.image<0) stream<<obj.image<<"i";
return stream;
}
istream& operator>>(istream& stream,COMPLEX& obj)
{
cout<<"Input real part:";
stream>>obj.real;
cout<<"input image part:";
stream>>obj.image;
return stream;
}
int main()
{
COMPLEX c1,c2;
cout<<"Input the first complex number c1:"<<endl;
cin>>c1;
cout<<"Input the second compex number c2:"<<endl;
cin>>c2;
cout<<"c1 is"<<c1<<endl;
cout<<"c2 is"<<c2<<endl;
cout<<"c1+c2 is "<<c2+c1<<endl;
cout<<"c1-c2 is "<<c1-c2<<endl;
//鎿嶄綔絎﹀師鍔熻兘浠誨瓨鍦?/span>
int a=50,b=10;
cout<<"A="<<a<<"\tB"<<b<<endl;
cout<<"A+B is "<<a+b<<endl;
cout<<"A-B is "<<a-b<<endl;
a=-b;
cout<<"A=-B,A="<<a<<"\tB"<<b<<endl;
a=b;
cout<<"A=B,A="<<a<<"\tB"<<b<<endl;
return 0;
}
杈撳嚭緇撴灉錛?br>
]]>