892.2022

1:

#include <bits/stdc++.h>
using namespace std;

int n;
int FFT(int n){
	int k = 1;
	for(int i = 0; i < n; i++){
		if(k >= n)
			return i; 
		k *= 2; 
	}
}
/*
//方法二,二进制下: 
int FFT(int n){
	for(int i = 0; i < n; i++){
		if(1 << i >= n) return i;
	}
}
*/
int main(){
	cin >> n;
	cout << FFT(n) << endl;
	return 0;
}

  

2:

 

#include <bits/stdc++.h>
using namespace std;

int main(){
	string s, ans;
	cin >> s;
	int l = s.length();
	int cnt = 1;//123334432
	for(int i = 0; i < l; i++){
		if(i + 1 < l && s[i] == s[i + 1]){
			cnt++;
		}else{
			if(cnt == 1){
				ans = ans + s[i];
			}else{
				ans = ans + s[i] + '-' + to_string(cnt);
			}
			cnt = 1;
		}
	}
	cout << ans << endl;
	return 0;
} 

  

3:

#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
long long check(int a[], int n){
	long long x, sum = 0;
	x = pow(2,32) - 1;
	for(int i = 0; i < n; i++){
		sum += a[i];
	}
	if(sum > x) return sum - x;
	else		return sum;
}

int main(){
	int a[N];
	cout << "输入数据的长度:" << endl;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	cout << check(a, n) << endl;
	return 0;
} 

  

4:

#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int Compare(string s1, string s2){
	int x = 0, y = 0;
	for(int i = 6; i <= 13; i++){
		if(s1[i] > s2[i])		return 1;
		else if(s1[i] < s2[i])	return -1;
	}
	return 0;
}

int main(){
	string s1, s2;
	cin >> s1 >> s2;
	cout << Compare(s1, s2) << endl;
	return 0;
} 

  

5:

#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
double BiaoZhunCha(double a[], int n){
	double M = 0, S = 0;
	for(int i = 0; i < n; i++){
		M += a[i];
	}
	M /= n;
	for(int i = 0; i < n; i++){
		S = S + (a[i] - M) * (a[i] - M);
	}
	S /= n;
	return sqrt(S);
}

int main(){
	double a[N];
	cout << "输入数据的长度:" << endl;
	cin >> n;
	cout << "输入数据:" << endl;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	cout << BiaoZhunCha(a, n) << endl;
	return 0;
} 

  

6:

#include <bits/stdc++.h>
using namespace std;
int select(double p[], int n){
	double sum[10005];
	sum[0] = p[0];
	for(int i = 1; i < n; i++){
		sum[i] = sum[i - 1] +  p[i]; 
	}
	int r = rand();
	r = rand();
	double p1 = (double)r / 32768;
	//cout << "p1 = " << p1 << endl;
	for(int i = n - 1; i >= 0; i--){
		if(p1 >= sum[i]) return i + 1;
	}
	return 0;
}
int main(){
	int n;
	double p[10005];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	cout << select(p, n) << endl;
	/*
	//3 0.5 0.2 0.3
	//用于检查 
	int cnt0 = 0, cnt1 = 0, cnt2 = 0;
	for(int i = 0; i < 10000; i++){
		int x = select(p, n);
		if(x == 0)		cnt0++;
		else if(x == 1)	cnt1++;
		else if(x == 2)	cnt2++;
	}
	printf("%d  %d  %d\n",cnt0,cnt1,cnt2);
	*/
	return 0;
}  

  

7:

#include <bits/stdc++.h>
using namespace std;
typedef struct Datetime{
	int year;
	int month;
	int day;
	int h, mi, s;
};
bool is_leap(int x){
	if(x % 400 == 0 || (x % 100 != 0 && x % 4 == 0)){
		return 1;
	}else return 0;
}
Datetime Datetime_convert(int n){
	int month[13] = {31,28,31,30,31,30,31,31,30,31,30,31};
	Datetime dt;
	int y = 1970, m = 1, day = 1, d, h = 0, mi = 0, s = 0;
	s = n % 60;
	mi = n / 60 % 60;
	h = n / 60 / 60 % 12;
	d = n /60 /60 /12; 
	while(1){
		if(is_leap(y)){
			if(d >= 366)	d -= 366;
			else	break;
		}else {
			if(d >= 365)	d -= 355;
			else	break;
		}
		y++;
	}
	if(is_leap(y)) month[1]++;
	for(int i = 0; i < 12; i++){
		if(d >= month[i]){
			m++;
			day++;
			d -= month[i];	
		}else break;
	}
	dt.year = y;
	dt.month = m;
	dt.day = day;
	dt.h = h;
	dt.mi = mi;
	dt.s = s;
	//printf("%d  %d  %d   %d  %d  %d\n",y,m,d,h,mi,s);
	return dt;
}

int main(){
	int n;
	cin >> n;
	Datetime dt = Datetime_convert(n);
	printf("%d  %d  %d   %d  %d  %d\n",dt.year,dt.month,dt.day,dt.h,dt.mi,dt.s);
	return 0;
} 

  

8:

 

posted @ 2022-11-27 21:57  荣荣荣荣荣荣  阅读(30)  评论(0)    收藏  举报