c ++ is sort sort
C or C ++ did not have a lot of powerful python libraries
so here is a new learning c ++ sort function
We sort code as an example ASCLL
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
char arr[3];
while(scanf("%c%c%c",&arr[0],&arr[1],&arr[2])!=EOF)
{
getchar();//尝试不用getchar函数,则会吞掉下一从输入的一个字符。
sort(arr,arr+3);
printf("%c %c %c",arr[0],arr[1],arr[2]);
}
return 0;
}
Here we must note getchar () function:
Because multiple sets of input, when the first line of input, such as: qew. The second row input
getchar function is equivalent to a \ n. So if there is no getchar words. N Enter program will also counts a string read. Then the result (to this problem, for example) will absorb the first two characters.
Fast power
Or use a description example
T^T(1)
Description
T ^ T This is much like a cry of expression is not it!
In fact, it is the power of friends ~ T-T. When T is relatively large when T ^ T will be very large, and now as long as you find a place this number can be friends!
Input
Input comprises a plurality of sets of test data, the test data is only one number for each T (0 <T <2 ^ {31}) T (0 <T <2 (31)).
Output
Please digit output of T ^ T.
Sample Input 1
1
2
3
105
Sample Output 1
1
4
7
5
#include <stdlib.h>
typedef long long ll;
ll fast(ll a, ll b)
{
int ans = 1;
while(b != 0)
{
if(b & 1)
{
ans *= a;
}
a = a * a;
b >>= 1;
}
return ans;
}
int main()
{
ll a, b, c;
scanf("%lld%lld", &a, &b);
c = fast(a, b);
printf("%lld", c);
return 0;
}
Note that the data type here