文章目录
- 1001 害死人不偿命的(3n+1)猜想
- 1002 写出这个数
- 1003 我要通过!
- 1004 成绩排名
- 1005 继续(3n+1)猜想
- 1006 换个格式输出整数
- 1007 素数对猜想
- 1008 数组元素循环右移问题
- 1009 说反话
- 1010 一元多项式求导
- 1011 A+B 和 C
- 1012 数字分类
- 1013 数素数
- 1014 福尔摩斯的约会
- 1015 德才论
- 1016 部分A+B
- 1017 A除以B
- 1018 锤子剪刀布
- 1019 数字黑洞
- 1020 月饼
- 1021 个位数统计
- D进制的A+B
- 1023 组个最小数
- 1024 科学计数法
- 1025 反转链表
- 1026 程序运行时间
- 1027 打印沙漏
- 1028 人口普查
- 1029 旧键盘
- 1030 完美数列
- 1031 查验身份证
- 1032 挖掘机技术哪家强
- 1033 旧键盘打字
- 1034 有理数四则运算
- 1035 插入与归并
- 1036 跟奥巴马一起编程
- 1037 在霍格沃茨找零钱
- 1038 统计同成绩学生
- 1039 到底买不买
- 1040 有几个PAT
- 1041 考试座位号
- 1042 字符统计
- 1043 输出PATest
- 1044 火星数字
- 1045 快速排序
- 1046 划拳
- 1047 编程团体赛
- 1048 数字加密
- 1049 数列的片段和
- 1050 螺旋矩阵
- 1051 复数乘法
- 1052 卖个萌
- 1053 住房空置率
- 1054 求平均值
- 1055 集体照
- 1056 组合数的和
- 1057 数零壹
- 1058 选择题
- 1059 C语言竞赛
- 1060 爱丁顿数
- 1061 判断题
- 1062 最简分数
- 1063 计算谱半径
- 1064 朋友数
- 1065 单身狗
- 1066 图像过滤
- 1067 试密码
- 1068 万绿丛中一点红
- 1069 微博转发抽奖
- 1070 结绳
- 1071 小赌怡情
- 1072 开学寄语
- 1073 多选题常见计分法
- 1074 宇宙无敌加法器
- 1075 链表元素分类
- 1076 Wifi密码
- 1077 互评成绩计算
- 1078 字符串压缩与解压
- 1079 延迟的回文数
- 1080 MOOC期终成绩
- 1081 检查密码
- 1082 射击比赛
- 1083 是否存在相等的差
- 1084 外观数列
- 1085 PAT单位排行
- 1086 就不告诉你
- 1087 有多少不同的值
- 1088 三人行
- 1089 狼人杀-简单版
- 1090 危险品装箱
- 1091 N-自守数
- 1092 最好吃的月饼
- 1093 字符串A+B
- 1094 谷歌的招聘
- 1095 解码PAT准考证
- 结语
1001 害死人不偿命的(3n+1)猜想

#include <cstdio>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
int step = 0;
while(n != 1)
{
if(n&1) n = n*3 + 1;
n >>= 1;
step++;
}
printf("%d\n",step);
return 0;
}
1002 写出这个数

#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
string s;
char t[1007];
map<int,string> mp;
ll ans = 0;
void init()
{
for(int i = 0; i <= 9; ++i)
{
if(i == 0) mp[i] = "ling";
if(i == 1) mp[i] = "yi";
if(i == 2) mp[i] = "er";
if(i == 3) mp[i] = "san";
if(i == 4) mp[i] = "si";
if(i == 5) mp[i] = "wu";
if(i == 6) mp[i] = "liu";
if(i == 7) mp[i] = "qi";
if(i == 8) mp[i] = "ba";
if(i == 9) mp[i] = "jiu";
}
}
int main()
{
init();
cin>>s;
int len = s.size();
for(int i = 0; i < len; i++)
ans += s[i] - '0';
int cnt = 0;
while(ans)
{
t[cnt++] = ans%10 + '0';
ans /= 10;
}
for(int i = cnt - 1; ~i; --i)
{
int x = t[i] - '0';
if(i == cnt-1) cout<<mp[x];
else cout<<" "<<mp[x];
}
cout<<'\n';
return 0;
}
1003 我要通过!

#include <iostream>
#include <string>
using namespace std;
string s;
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>s;
int len = s.size();
int pos1 = 0, pos2 = 0, okP = 0;
for(int i = 0; i < len; ++i)
{
if(s[i] == 'P' && !okP) pos1 = i, okP = 1;
if(s[i] == 'T' && okP == 1) pos2 = i, okP = 2;
}
if(okP != 2) cout<<"NO"<<'\n';
else
{
int x = 0, y = 0, z = 0;
for(int i = 0; i < pos1; ++i)
{
if(s[i] == 'A') x++;
else
{
x = -0x3f3f3f3f;
break;
}
}
for(int i = pos1 + 1; i < pos2; ++i)
{
if(s[i] == 'A') y++;
else
{
y = 0;
break;
}
}
for(int i = pos2 + 1; i < len; ++i)
{
if(s[i] == 'A') z++;
else
{
z = 0;
break;
}
}
if(!y || x*y != z) cout<<"NO"<<'\n';
else cout<<"YES"<<'\n';
}
}
return 0;
}
1004 成绩排名

#include <bits/stdc++.h>
using namespace std;
struct node
{
string name,id;
int core;
bool operator < (const node & t) const{
return core < t.core;
}
}a[1007];
int main()
{
int n;
cin>>n;
for(int i = 0; i < n; ++i) cin>>a[i].name>>a[i].id>>a[i].core;
sort(a,a+n);
cout<<a[n-1].name<<" "<<a[n-1].id<<'\n';
cout<<a[0].name<<" "<<a[0].id<<'\n';
return 0;
}
1005 继续(3n+1)猜想

把 2 ~ 100 中运算过程中覆盖的数字求出来,用set存,开个标记数组,把输入的数从大向小找,如果 输入的数是出现在覆盖了的表中,然后标记一下,最后看哪些数没有被覆盖。
#include <cstdio>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 7;
int a[107];
set<int> st[100];
int vis[maxn];
int ans[107];
void init()
{
for(int i = 2; i < 100; i++)
{
int t = i;
while(t != 1)
{
if(t&1) t = t*3 + 1;
t >>= 1;
st[i].insert(t);
}
}
}
int main()
{
init();
int n;
scanf("%d",&n);
for(int i = 0; i < n; ++i) scanf("%d",&a[i]);
sort(a,a+n);
for(int i = n-1; i >= 0; --i)
{
for(int j = 0; j < n; ++j)
{
if(st[a[i]].find(a[j])!= st[a[i]].end()) vis[a[j]] = 1;
}
}
int idx = 0;
for(int i = 0; i < n; ++i)
if(!vis[a[i]]) ans[idx++] = a[i];
sort(ans,ans+idx);
for(int i = idx-1; i >= 0; --i)
{
if(i == idx-1) printf("%d",ans[i]);
else printf(" %d",ans[i]);
}
return 0;
}
1006 换个格式输出整数

#include <cstdio>
using namespace std;
int main()
{
int n;
scanf("%d\n",&n);
int b,s,g;
g = n%10;
n/=10;
s = n%10;
n/=10;
b = n;
for(int i = 0; i < b; ++i) printf("B");
for(int i = 0; i < s; ++i) printf("S");
for(int i = 1; i <= g; ++i) printf("%d",i);
return 0;
}
1007 素数对猜想

线性素数筛
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 7;
bool st[maxn];
int primes[maxn],cnt = 0;
void Get_primes()
{
for(int i = 2; i <= maxn; ++i)
{
if(!st[i]) primes[cnt++] = i;
for(int j = 0; primes[j] <= maxn/i; ++j)
{
st[primes[j]*i] = true;
if(i%primes[j] == 0) break;
}
}
}
int main()
{
Get_primes();
int n, cnt = 0;
scanf("%d",&n);
for(int i = 1; primes[i] <= n; i++)
if(primes[i] - primes[i-1] == 2) cnt++;
printf("%d\n",cnt);
return 0;
}
1008 数组元素循环右移问题

#include <iostream>
using namespace std;
const int maxn = 110;
int a[maxn], b[maxn];
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i = 0; i < n; i++) scanf("%d",&a[i]);
for(int i = 0; i < n; i++) b[(i+m)%n] = a[i];
for(int i = 0; i < n; i++)
if(!i) printf("%d",b[i]);
else printf(" %d",b[i]);
return 0;
}
1009 说反话

#include <bits/stdc++.h>
using namespace std;
int main()
{
string s="";
getline(cin,s);
for(int i = s.size()-1; i >= 0; --i)
{
string t = "";
while(s[i] != ' ' && i >= 0)
{
t += s[i];
--i;
}
for(int j = t.size()-1; j >= 0; --j) cout<<t[j];
if(i>=0) cout<<" ";
}
return 0;
}
1010 一元多项式求导

用 g e t l i n e getline getline 读入然后去转换会莫名的 w a wa wa 掉一部分数据。
#include <iostream>
using namespace std;
int a[110],b[110];
int c[110],d[110];
int main()
{
int cnt = 0;
while(cin>>a[cnt]>>b[cnt])
{
if(b[cnt] == 0) break;
cnt++;
}
int idx = 0;
if(!cnt)
cout<<"0 0"<<endl;
else
{
for(int i = 0; i < cnt; ++i)
{
c[idx] = a[i]*b[i];
d[idx++] = b[i] - 1;
}
for(int i = 0; i < idx; ++i)
if(!i) cout<<c[i]<<" "<<d[i];
else cout<<" "<<c[i]<< " "<<d[i];
cout<<endl;
}
return 0;
}
1011 A+B 和 C

#include <iostream>
using namespace std;
int main()
{
long long a,b,c;
int t;
cin>>t;
for(int i = 1; i <= t; i++)
{
cin>>a>>b>>c;
cout<<"Case #"<<i<<": ";
if(a+b > c) cout<<"true"<<'\n';
else cout<<"false"<<'\n';
}
return 0;
}
1012 数字分类

#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int a[1007], b[1007];
int main()
{
int n;
cin>>n;
for(int i = 0; i < n; i++) cin>>a[i];
int A = 0, B = 0, c = 0, d = 0, e = 0;
int sum = 0,cnt = 0;
for(int i = 0; i < n; ++i)
{
if(a[i]%5 == 0 && a[i]%2 == 0) A += a[i];
if(a[i]%5 == 1) b[cnt++] = a[i];
if(a[i]%5 == 2) c++;
if(a[i]%5 == 3) d++, sum += a[i];
if(a[i]%5 == 4) e = max(e,a[i]);
}
for(int i = 0; i < cnt; i+=2)
B = B + b[i] - b[i+1];
if(!A) cout<<"N ";
else cout<<A<<" ";
if(!cnt) cout<<"N ";
else cout<<B<<" ";
if(!c) cout<<"N ";
else cout<<c<<" ";
if(!d) cout<<"N ";
else cout<<setiosflags(ios::fixed)<<setprecision(1)<<(double)sum/d<<" ";
if(!e) cout<<"N";
else cout<<e;
return 0;
}
1013 数素数

素数线性筛法
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
const int maxn = 1e6 + 7;
bool st[maxn];
int cnt;
int primes[maxn];
void Get_primes()
{
for(int i = 2; i <= maxn; ++i)
{
if(!st[i]) primes[cnt++] = i;
for(int j = 0; primes[j] <= maxn/i; ++j)
{
st[primes[j]*i] = true;
if(i%primes[j] == 0) break;
}
}
}
int main()
{
Get_primes();
int n,m;
scanf(" %d%d",&n,&m);
if(m > n) swap(m,n);
int count = 0;
/***
int k = 0;
for(int i = 2; i <= maxn; ++i) if(!st[i]) k++;
printf("%d\n",k);
***/
for(int i = m; i <= n; ++i)
{
count++;
if(count == 1) printf("%d",primes[i-1]);
else printf(" %d",primes[i-1]);
if(count == 10) puts(""), count = 0;
}
return 0;
}
1014 福尔摩斯的约会

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
string a,b,c,d;
map<char,string> mp;
map<char,int> S;
void init()
{
mp['A'] = "MON"; mp['B'] = "TUE"; mp['C'] = "WED"; mp['D'] = "THU";
mp['E'] = "FRI"; mp['F'] = "SAT"; mp['G'] = "SUN";
char s = 'A', t = '0';
for(int i = 0; i < 24; i++)
{
if(i < 10) S[t] = i, t++;
if(i >= 10) S[s] = i, s++;
}
}
int main()
{
init();
cin>>a>>b>>c>>d;
int lena = a.size(), lenb = b.size(), lenc = c.size(), lend = d.size();
int pos = 0, cnt = 0;
int len1 = min(lena,lenb), len2 = min(lenc,lend);
char x='0', y='0';
for(int i = 0; i < len1; ++i)
{
if(a[i] == b[i] && a[i] >= 'A' && a[i] <= 'G' && !cnt) cnt++, x = a[i];
else if(a[i] == b[i] && cnt == 1 && ((a[i] >= 'A' && a[i] <= 'N')|| (a[i] >= '0' && a[i] <= '9')) ) y = a[i],cnt++;
if(cnt == 2) i = len1;
}
for(int i = 0; i < len2; ++i)
if(c[i] == d[i] && ((c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z'))) pos = i, i = len2;
cout<<mp[x]<<" ";
if(S[y] < 10) cout<<"0"<<S[y]<<":";
else cout<<S[y]<<":";
if(pos < 10) cout<<"0"<<pos<<'\n';
else cout<<pos<<'\n';
return 0;
}
1015 德才论

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
struct node{
int id,d,c;
bool operator < (const node &t) const{
if(d+c != t.d + t.c) return (d+c) > (t.d+t.c);
if(d != t.d) return d > t.d;
return id < t.id;
}
};
node a[maxn];
vector<node>v[5];
int main()
{
int n,h,l,cnt = 0;
scanf("%d%d%d",&n,&l,&h);
for(int i = 0; i < n; ++i)
{
scanf("%d%d%d",&a[i].id,&a[i].d,&a[i].c);
if(a[i].d >= l && a[i].c >=l) cnt++;
if(a[i].d < l || a[i].c < l) continue;
else if(a[i].d >= h && a[i].c >= h) v[0].push_back(a[i]);
else if(a[i].c < h && a[i].d >= h) v[1].push_back(a[i]);
else if(a[i].d < h && a[i].c < h && a[i].d >= a[i].c) v[2].push_back(a[i]);
else v[3].push_back(a[i]);
}
printf("%d\n",cnt);
for(int i = 0; i < 4; ++i)
{
sort(v[i].begin(),v[i].end());
for(auto it : v[i]) printf("%d %d %d\n",it.id,it.d,it.c);
}
return 0;
}
1016 部分A+B

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int work(ll x, int y)
{
int a[10] = {
0};
while(x)
{
int t = x%10;
a[t]++;
x /= 10;
}
return a[y];
}
int change(int x,int num)
{
if(!num) return 0;
int t = x;
for(int i = 1; i < num; ++i)
x = x*10 + t;
return x;
}
int main()
{
ll A,B; int x,y;
cin>>A>>x>>B>>y;
int ansx = work(A,x), ansy = work(B,y);
int xx = change(x,ansx), yy = change(y,ansy);
ll ans = (ll)(xx + yy);
cout<<ans<<'\n';
return 0;
}
1017 A除以B

#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int>v;
int main()
{
string s; int t;
cin>>s>>t;
int len = s.size();
int temp = 0, yu = 0;
for(int i = 0; i < len; ++i)
{
temp = temp*10 + s[i] - '0';
int x = temp/t;
temp %= t;
v.push_back(x);
if(i == len-1) yu = temp;
}
int pos = 0;
if(!v[0] && v.size() > 1) pos++;
for(int i = pos; i < v.size(); ++i) cout<<v[i];
cout<<" "<<yu<<'\n';
return 0;
}
1018 锤子剪刀布

输入样例
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
输出样例
5 3 2
2 3 5
B B
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 7;
vector<char>a,b;
int s[4],t[4];
int main()
{
int n;
scanf("%d",&n);
for(int i = 0; i < n; ++i)
{
char x,y;
scanf(" %c %c",&x,&y);
if(x == y) s[1]++,t[1]++;
else
{
if((x == 'C' && y == 'J')||(x == 'J' && y == 'B') || (x == 'B' && y == 'C'))
s[0]++,t[2]++,a.push_back(x);
if((x == 'C' && y == 'B')||(x == 'J' && y == 'C') || (x == 'B' && y == 'J'))
t[0]++,s[2]++,b.push_back(y);
}
}
for(int i = 0; i < 3; i++)
if(!i) printf("%d",s[i]);
else printf(" %d",s[i]);
puts("");
for(int i = 0; i < 3; i++)
if(!i) printf("%d",t[i]);
else printf(" %d",t[i]);
puts("");
int bb1 = 0, bb2 = 0, cc1 = 0, cc2 = 0, jj1 = 0, jj2 = 0;
for(auto &i : a)
{
if(i == 'B') bb1++;
if(i == 'C') cc1++;
if(i == 'J') jj1++;
}
for(auto &i : b)
{
if(i == 'B') bb2++;
if(i == 'C') cc2++;
if(i == 'J') jj2++;
}
if(bb1 >= cc1 && bb1 >= jj1) cout<<"B";
else if(cc1 > bb1 && cc1 >= jj1) cout<<"C";
else if(jj1 > bb1 && jj1 > cc1) cout<<"J";
cout<<" ";
if(bb2 >= cc2 && bb2 >= jj2) cout<<"B";
else if(cc2 > bb2 && cc2 >= jj2) cout<<"C";
else if(jj2 > bb2 && jj2 > cc2) cout<<"J";
cout<<'\n';
return 0;
}
1019 数字黑洞

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[4];
string changex(string x)
{
for(int i = 0; i < 4; i++)
a[i] = (int)(x[i] - '0');
sort(a,a+4);
string ans = "";
for(int i = 0; i < 4; ++i) ans += char(a[i]+'0');
return ans;
}
string changed(string x)
{
for(int i = 0; i < 4; i++)
a[i] = x[i] - '0';
sort(a,a+4);
string ans = "";
for(int i = 3; ~i; --i) ans += char(a[i] + '0');
return ans;
}
string cal(string x, string y)
{
int ok = 0;
string ans = "";
for(int i = 3; ~i; --i)
{
int t1 = x[i] - '0', t2 = y[i] - '0';
if(ok) t1--, ok = 0;
if(t1

最低0.47元/天 解锁文章
7187

被折叠的 条评论
为什么被折叠?



