L1-026
Ideas:
output once again wrap
the code:
#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
Ideas:
Mapping look to
the code:
#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
Ideas:
Society
Complexity is determined prime
Code:
#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
Thinking:
According to mean calculation
codes:
#include<bits/stdc++.h>
using namespace std;
int main() {
double h;
cin >> h;
printf("%.1f", (h - 100) * 1.8);
return 0;
}
L1-030
Ideas:
in the end output from the high-ranking, need to meet the lowest-ranked boys / girls; boys and girls about maintaining the current minimum is one who will line;
Code:
#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;
}