ICBC

71

ICBC
7天前
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 100010;
int arr[N], ans, mid;
int main()
{
int n;
cin>>n;
for (int i = 0; i < n; i ++ )
cin>> arr[i];
sort(arr, arr + n);
mid = arr[n>>1];
for (int i = 0; i < n; i ++ )
ans += abs(arr[i] - mid);
cout<<ans;
return 0;

}

ICBC
7天前

#include<iostream>
using namespace std;
const int N = 643010;
int main()
{
int arr[N]={1};
int n;
cin>>n;
int m=1;
for (int i = 0;i < n; i ++ )
{2
int t = 0;
for (int j = 0; j < m; j ++ )
{
t += arr[j] * 2;
arr[j] = t % 10;
t /= 10;

}
if (t) arr[m ++ ] = 1;
}
for (int i = m - 1; i >= 0; i -- ) cout << arr[i];
cout << endl;
return 0;
}

ICBC
7天前

# 关于数组旋转

n个数据顺时针旋转k次

cin>>arr[(i+k)%n]

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int arr[n];
for(int i = 0 ; i < n ; i ++)
{
cin>>arr[(i+k)%n];
}
for(int i = 0 ; i < n ; i ++)
{
cout<<arr[i]<<endl;
}
return 0;

}

——————————————————----

----——————————————

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int arr[n];
for(int i = 0 ; i < n ; i ++)
{
cin>>arr[i];
}
reverse(arr, arr + n);
reverse(arr, arr + k);
reverse(arr + k, arr + n);
for(int i = 0; i < n; i ++) cout<<arr[i]<<endl;

return 0;

}