グループプログラミングラダーマッチL1-026〜L1-030

L1-026

アイデア:

出力もう一度ラップ

コードを:

#include<bits/stdc++.h>

using namespace std;

int main() {
	string s = "I Love GPLT";
	for(char & c : s) {
		putchar(c);
		putchar('\n');	
	}
	return 0;
}

L1-027

アイデア:

へのマッピングを見て

コード:

#include<bits/stdc++.h>

using namespace std;

int cnt[15], pos[15];
void out(vector<int> & v){ cout << v[0]; for(int i = 1; i < v.size(); ++i) putchar(','), cout << v[i]; cout << "};\n"; }

int main() {
	string s;
	cin >> s;
	for(char & c : s) ++cnt[c- '0'];
	vector<int> rcd, pos(15), tel;
	for(int i = 10; i >= 0; --i) if(cnt[i]) pos[i] = rcd.size(), rcd.push_back(i);
	cout << "int[] arr = new int[]{";
	out(rcd);
	for(char & c : s) tel.push_back(pos[c - '0']);
	cout << "int[] index = new int[]{";
	out(tel);
	return 0;
}

L1-028

アイデア:

社会 ザ・ n個 (\のSqrt {N}) 複雑さはプライム決定され

コード:

#include<bits/stdc++.h>

using namespace std;

bool isPrime(int n){
	int sq = sqrt(n);
	for(int i = 2; i <= sq; i++){
		if(n % i == 0) return false;
	}
	return n != 1;
}

int main() {
	int kase, n;
	cin >> kase;
	while(kase--){
		cin >> n;
		puts(isPrime(n) ? "Yes" : "No");	
	}
	return 0;
}

L1-029

思考:

平均の計算によると、

コード:

#include<bits/stdc++.h>

using namespace std;

int main() {
	double h;
	cin >> h;
	printf("%.1f", (h - 100) * 1.8);
	return 0;
}

L1-030

アイデア:

最低ランクの男の子/女の子満たすために、高ランクの、必要性からエンド出力に、現在の最小の維持についての男の子と女の子を裏打ちするものである。

コード:

#include<bits/stdc++.h>

using namespace std;
typedef pair<string, int> P;
#define pb(x) push_back(x) 

int main() {
	int n;
	cin >> n;
	vector<string> boy, girl;
	vector<pair<string, int> > tot; 
	for(int i = 0; i < n; i++){
		int x;
		string s;
		cin >> x >> s;
		if(x) boy.pb(s); else girl.pb(s);
		tot.pb(P(s, x));	
	}
	int x = n / 2, y = x;  //boy girl
	map<string, bool> vst;
	for(P & p : tot){
		string now = p.first;
		if(vst[now]) continue;
		if(p.second){
			cout << now << ' ' << girl[--y] << '\n';
			vst[girl[y]] = true;
		}else{
			cout << now << ' ' << boy[--x] << '\n';
			vst[boy[x]] = true;
		}
	}
	return 0;
}
公開された281元の記事 ウォン称賛7 ビュー6717

おすすめ

転載: blog.csdn.net/qq_45228537/article/details/103979073