T1
map的简单运用,或者读进来再一个一个判断就行。
#include<bits/stdc++.h>
using namespace std;
map<char ,int> m;
int a[9];
int main () {
m['1'] = 1;
m['A'] = 1;
m['Q'] = 1;
m['Z'] = 1;
m['2'] = 2;
m['W'] = 2;
m['S'] = 2;
m['X'] = 2;
m['3'] = 3;
m['E'] = 3;
m['D'] = 3;
m['C'] = 3;
m['R'] = 4;
m['4'] = 4;
m['F'] = 4;
m['V'] = 4;
m['5'] = 4;
m['T'] = 4;
m['G'] = 4;
m['B'] = 4;
m['6'] = 5;
m['Y'] = 5;
m['H'] = 5;
m['N'] = 5;
m['7'] = 5;
m['U'] = 5;
m['J'] = 5;
m['M'] = 5;
m['8'] = 6;
m['I'] = 6;
m['K'] = 6;
m[','] = 6;
m['9'] = 7;
m['O'] = 7;
m['L'] = 7;
m['.'] = 7;
string s;
cin >> s;
for(int i = 0 ; i < s.size() ; i ++){
if(!m[s[i]])a[8] ++;
else a[m[s[i]]] ++;
}
for(int i = 1 ; i <= 8 ; i ++){
cout << a[i] <<endl;
}
}
T2
当n > m 的时候,每个人都分到一根,再分剩下的
当m > n 的时候,如果m % n == 0每个人能分得n / m ,就是要砍 (m / n - 1 ) * n 刀
否则砍m刀
#include<bits/stdc++.h>
using namespace std;
int n , m;
int ans;
int main () {
cin >> n >> m;
while(n % m != 0){
if(n > m) n %= m;
int k = m % n == 0 ? m / n - 1 : m / n;
m = m % n ;
ans += k * n;
if(m == 0)break;
}
cout << ans << endl;
}
T3
按照右端点排序,左端点先开始并且大于上一个已选活动的结束,就可以加入这个活动
#include<bits/stdc++.h>
using namespace std;
int m ;
struct node{
int l , r;
}a[10020];
int n ;
bool cmp(node x , node y){
return x.r < y.r;
}
int b[10020];
int sum[100020];
int main () {
cin >> m;
while(m --){
cin >> n;
int ans = 0 ;
for(int i = 1 ; i <= n ; i ++){
scanf("%d%d" , &a[i].l , &a[i].r);
}
sort(a + 1 , a + 1 + n , cmp);
ans = 1;
int k = 1;
for(int i = 2 ; i <= n ; i ++){
if(a[i].l >= a[k].r){
ans ++ ;
k = i;
}
}
cout << ans << endl;
}
}
T4
从里到外,显然递归,就遇到左括号开始递归,遇到右括号就返回即可
#include<bits/stdc++.h>
using namespace std;
string calc(){
int k ;
string s1 = "" , s2 = "";
char ch ;
while(cin >> ch){
if(ch == '['){
cin >> k ;
s2 = calc();
while(k --)s1 += s2;
}
else if(ch == ']'){
return s1;
}
else{
s1 += ch;
}
}
}
int main () {
cout << calc() ;
}
T5
按照a * b 排序,最后用高精度即可,高精乘以单精,高精除以单精度
#include<bits/stdc++.h>
using namespace std;
struct node{
long long l , r;
}p[10020];
bool cmp(node x , node y){
return x.l * x.r < y.l * y.r;
}
long long n;
long long c1[10200] ;
long long c2[10200] ;
long long c3[10200] ;
void mul(long long x){
for(int i = 1 ; i <= 10200-1 ; i ++){
c1[i] *= x;
}
for(int i = 1 ; i <= 10200-1 ; i ++){
c1[i + 1] += c1[i] / 10;
c1[i] %= 10;
}
int l = 10200-1 ;
while(c1[l] == 0){
l --;
}
/* for(int i = l ; i >= 1; i --){
cout << c1[i];
}
cout << endl;*/
}
int len1 = 1 , len2 = 1;
void div(long long x){
memset(c2 , 0 , sizeof c2);
int tmp = 0;
for(int i = 10200-1 ; i >= 1 ; i --){
tmp *= 10 ;
tmp += c1[i];
if(tmp >= x){
c2[i] = tmp / x;
tmp %= x;
}
}
len1 = 10200-1;
while(c2[len1] <= 0 ){
len1 -- ;
if(len1 == 1)break;
}
}
void fans(){
if(len1 > len2){
for(int i = 1 ;i <= len1; i ++){
c3[i] = c2[i];
}
len2 = len1;
}
else if(len1 < len2)return ;
else if(len1 == len2){
for(int i = len1 ;i >= 1; i --){
if(c2[i] > c3[i]){
for(int j = len1 ;j >= 1; j --){
c3[j] = c2[j];
}
len2 = len1;
break;
}
}
}
}
int main () {
c1[1] = 1;
cin >> n ;
cin >> p[0].l >> p[0].r;
for(int i = 1; i <= n ; i ++){
cin >> p[i].l >> p[i].r;
}
sort(p + 1 , p + 1 + n , cmp);
for(int i = 1; i <= n ; i ++){
mul(p[i - 1].l);
div(p[i].r);
fans();
}
for(int i = len2 ; i >= 1; i --){
cout << c3[i];
}
/*
3
23113 513
213315 5163515
5163516556 15155
5163516556 15155
*/
}
标签:node,第三次,int,cin,long,--,双周,cout From: https://www.cnblogs.com/wmjlzw1314/p/16979242.html