L1-001 Hello World (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805147132084224
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f; int main(){
printf("Hello World!\n");
return ;
}
L1-002 打印沙漏 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805145370476544
思路:利用等差数列求和,算出利用当前N 最多可以搭建的层数(单侧) 然后模拟
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n;
char x; int main(){
scanf("%d %c",&n,&x);
int pos=;
while(((+(*pos+))*pos+*(*(pos+)+))<(n-)){
pos++;
}
// printf("%d\n",pos);
for(int i=;i<=pos;i++){
for(int j=;j<i;j++){
printf(" ");
}
for(int j=;j<*pos+-*i;j++){
printf("%c",x);
}
printf("\n");
}
for(int i=pos-;i>=;i--){
for(int j=;j<i;j++){
printf(" ");
}
for(int j=;j<*pos+-*i;j++){
printf("%c",x);
}
printf("\n");
}
printf("%d\n",n-((+*pos+)*pos+));
return ;
}
L1-003 个位数统计 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805143738892288
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int cnt[];
char s[maxn]; int main(){
scanf("%s",s);
int len=strlen(s);
memset(cnt,,sizeof(cnt));
for(int i=;i<len;i++){
cnt[s[i]-'']++;
}
for(int i=;i<=;i++){
if(cnt[i]!=)
printf("%d:%d\n",i,cnt[i]);
}
return ;
}
L1-004 计算摄氏温度 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805142086336512
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
printf("Celsius = %d\n",*(n-)/);
return ;
}
L1-005 考试座位号 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805140211482624
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n,m,x; struct node{
char a[];
int b,c;
}kk[maxn]; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s %d %d",kk[i].a,&kk[i].b,&kk[i].c);
}
scanf("%d",&m);
for(int i=;i<=m;i++){
scanf("%d",&x);
for(int j=;j<=n;j++){
if(x==kk[j].b){
printf("%s %d\n",kk[j].a,kk[j].c);
}
}
}
return ;
}
L1-006 连续因子 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805138600869888
思路:枚举可能开始连续的位置j 对于每个j都判断能否组成N 如果可以 纪录长度取max
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
ll n; int main(){
scanf("%lld",&n);
ll sum=;
int st=,len=;
for(int i=;i<=sqrt(n);i++){
sum=;
for(int j=i;j*sum<=n;j++){
sum*=j;
if(n%sum== && j-i+>len){
st=i;
len=j-i+;
}
}
}
if(st==){
st=n;
len=;
}
printf("%d\n%d",len,st);
for(int i=st+;i<st+len;i++){
printf("*%d",i);
}
printf("\n");
return ;
}
L1-007 念数字 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805136889593856
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
char n[]; int main(){
scanf("%s",n);
int len=strlen(n);
string s[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
if(n[]=='-'){
printf("fu ");
for(int i=;i<len-;i++){
cout<<s[n[i]-'']<<" ";
}
cout<<s[n[len-]-'']<<endl;
}
else{
for(int i=;i<len-;i++){
cout<<s[n[i]-'']<<" ";
}
cout<<s[n[len-]-'']<<endl;
} return ;
}
L1-008 求整数段和 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805135224455168
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int a,b; int main(){
scanf("%d%d",&a,&b);
int cnt=,sum=;
for(int i=a;i<=b;i++){
cnt++;
sum+=i;
printf("%5d",i);
if(cnt==){
printf("\n");
cnt=;
}
}
if((b-a+)%!=) printf("\n");
printf("Sum = %d\n",sum);
return ;
}
L1-009 N个数求和 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805133597065216
思路:在通分的时候会爆int 选择了用long double 先除后乘
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n;
ll a[maxn],b[maxn]; int main(){
(void)scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%lld/%lld",&a[i],&b[i]);
}
ll sum1=a[],sum2=b[];
for(int i=;i<=n;i++){
ll tmp=__gcd(sum2,b[i]);
ll ans=(long double)sum2/(long double)tmp*b[i];
sum1=(long double)a[i]/(long double)b[i]*ans+(long double)sum1/(long double)sum2*ans;
sum2=ans;
ll tmp2=__gcd(sum1,sum2);
//int ans2=sum1*sum2/tmp2;
sum1/=tmp2;
sum2/=tmp2;
}
ll t=;
t=sum1/sum2;
sum1-=t*sum2;
if(t== && sum1!=) printf("%lld/%lld\n",sum1,sum2);
else if(t!= && sum1!=) printf("%lld %lld/%lld\n",t,sum1,sum2);
else if(sum1==) printf("%lld\n",t);
return ;
}
L1-010 比较大小 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805132040978432
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int a[]; int main(){
scanf("%d%d%d",&a[],&a[],&a[]);
sort(a,a+);
printf("%d->%d->%d\n",a[],a[],a[]);
return ;
}
L1-011 A-B (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805130426171392
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int cnt[];
string a,b; int main(){
getline(cin,a);
getline(cin,b);
for(int i=;i<b.length();i++){
cnt[b[i]]=;
}
for(int i=;i<a.length();i++){
if(cnt[a[i]]==) continue;
cout<<a[i];
}
cout<<endl;
return ;
}
L1-012 计算指数 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805128870084608
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
int a=pow(,n);
printf("2^%d = %d\n",n,a);
return ;
}
L1-013 计算阶乘和 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805127389495296
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++){
int tmp=;
for(int j=;j<=i;j++){
tmp*=j;
}
sum+=tmp;
}
printf("%d\n",sum);
return ;
}#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++){
int tmp=;
for(int j=;j<=i;j++){
tmp*=j;
}
sum+=tmp;
}
printf("%d\n",sum);
return ;
}#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++){
int tmp=;
for(int j=;j<=i;j++){
tmp*=j;
}
sum+=tmp;
}
printf("%d\n",sum);
return ;
}#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++){
int tmp=;
for(int j=;j<=i;j++){
tmp*=j;
}
sum+=tmp;
}
printf("%d\n",sum);
return ;
}#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++){
int tmp=;
for(int j=;j<=i;j++){
tmp*=j;
}
sum+=tmp;
}
printf("%d\n",sum);
return ;
}
L1-014 简单题 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805125929877504
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f; int main(){
printf("This is a simple problem.\n");
return ;
}
L1-015 跟奥巴马一起画方块 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805124398956544
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n;
char x; int main(){
scanf("%d %c",&n,&x);
int m;
if(n%==) m=n/+;
else m=n/;
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
printf("%c",x);
}
printf("\n");
}
return ;
}
L1-016 查验身份证 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805122985476096
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n,ans[];
char s[][]; const int a[]={,,,,,,,,,,,,,,,,};
const int b[]={,,'X'-'',,,,,,,,}; int main(){
scanf("%d",&n);
int flag=;
for(int id=;id<=n;id++){
scanf("%s",s[id]);
int sum=,cnt=;
for(int i=;i<;i++){
if(s[id][i]-''< || s[id][i]-''>) cnt++;
else sum+=((s[id][i]-'')*a[i]);
}
// printf("%d\n",cnt);
if(cnt!=){
ans[flag++]=id;
continue;
}
else{
sum%=;
if(s[id][]-''!=b[sum]) ans[flag++]=id;
}
}
if(flag==){
printf("All passed\n");
}
else{
for(int i=;i<flag;i++){
printf("%s\n",s[ans[i]]);
}
}
return ;
}
L1-017 到底有多二 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805121500692480
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
char s[]; int main(){
scanf("%s",s);
int len=strlen(s);
int n=len,cnt=;
double tmp=1.0;
if(s[]=='-'){
n--;
tmp=1.5;
}
for(int i=;i<len;i++){
if(s[i]-''==) cnt++;
}
int flag=;
if((s[len-]-'')%==) flag=;
double ans=(double)cnt/(double)n*tmp*flag*;
printf("%.2f%%\n",ans);
return ;
}
L1-018 大笨钟 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805119944605696
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int hh,mm; int main(){
scanf("%d:%d",&hh,&mm);
if(hh>= && hh<=) printf("Only %02d:%02d. Too early to Dang.\n",hh,mm);
else{
if(mm==){
for(int i=;i<=hh-;i++){
printf("Dang");
}
printf("\n");
}
else{
for(int i=;i<=hh-+;i++){
printf("Dang");
}
printf("\n");
}
}
return ;
}
L1-019 谁先倒 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805118568873984
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int a,b,n;
int x[maxn],y[maxn],xx[maxn],yy[maxn]; int main(){
scanf("%d%d",&a,&b);
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&x[i],&xx[i],&y[i],&yy[i]);
}
int suma=,sumb=;
for(int i=;i<=n;i++){
if(x[i]+y[i]==xx[i] && x[i]+y[i]!=yy[i]){
suma++;
if(suma>a) break;
}
if(x[i]+y[i]==yy[i] && x[i]+y[i]!=xx[i]){
sumb++;
if(sumb>b) break;
}
}
if(suma>a) printf("A\n%d\n",sumb);
if(sumb>b) printf("B\n%d\n",suma);
return ;
}
L1-020 帅到没朋友 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805117167976448
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e6+;
int n,m,k,x,b;
int vis[maxn]; int main(){
while(~scanf("%d",&n)){
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++){
scanf("%d",&k);
for(int j=;j<=k;j++){
scanf("%d",&x);
if(k==) break;
vis[x]=;
}
}
scanf("%d",&m);
int cnt=;
for(int i=;i<=m;i++){
scanf("%d",&b);
if(vis[b]==){
if(++cnt>) printf(" ");
printf("%05d",b);
vis[b]=;
}
}
if(cnt==) printf("No one is handsome");
printf("\n");
}
return ;
}
L1-021 重要的话说三遍 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805115792244736
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f; int main(){
printf("I'm gonna WIN!\nI'm gonna WIN!\nI'm gonna WIN!\n");
return ;
}
L1-022 奇偶分家 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805114445873152
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n,x; int main(){
scanf("%d",&n);
int sum1=,sum2=;
for(int i=;i<=n;i++){
scanf("%d",&x);
if(x%==) sum1++;
else sum2++;
}
printf("%d %d\n",sum1,sum2);
return ;
}
L1-023 输出GPLT (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805113036587008
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
int cnt[];
char s[maxn]; int main(){
scanf("%s",s);
memset(cnt,,sizeof(cnt));
int len=strlen(s);
for(int i=;i<len;i++){
if(s[i]=='G' || s[i]=='g') cnt[]++;
if(s[i]=='P' || s[i]=='p') cnt[]++;
if(s[i]=='L' || s[i]=='l') cnt[]++;
if(s[i]=='T' || s[i]=='t') cnt[]++;
}
// printf("%d %d %d %d\n",cnt[1],cnt[2],cnt[3],cnt[4]);
int tmp=max(cnt[],max(cnt[],max(cnt[],cnt[])));
for(int i=;i<=tmp;i++){
if(cnt[]>){
printf("G");
cnt[]--;
}
if(cnt[]>){
printf("P");
cnt[]--;
}
if(cnt[]>){
printf("L");
cnt[]--;
}
if(cnt[]>){
printf("T");
cnt[]--;
}
}
printf("\n");
return ;
}
L1-024 后天 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805111694409728
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
n=n+;
if(n>) n=n%;
printf("%d\n",n);
return ;
}
L1-025 正整数A+B (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805110318678016
思路:需要判断各种不符合的输入 包括小于1和大于一千的数据
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
char a[maxn];
string b; int main(){
scanf("%s ",a);
getline(cin,b);
int lena=strlen(a),lenb=b.length();
int flaga=,flagb=;
for(int i=;i<lena;i++){
if(a[i]-''< || a[i]-''>) flaga=;
}
for(int i=;i<lenb;i++){
if(b[i]-''< || b[i]-''>) flagb=;
}
int tmpa=,tmpb=,tmp=;
if(flaga== && flagb==){
for(int i=;i<lena;i++){
tmpa=tmpa*+(a[i]-'');
}
for(int i=;i<lenb;i++){
tmpb=tmpb*+(b[i]-'');
}
if(tmpa< || tmpa>) flaga=;
if(tmpb< || tmpb>) flagb=;
if(flaga== && flagb==) tmp=tmpa+tmpb;
}
if(flaga== && flagb==){
printf("%s + ",a);
cout<<b;
printf(" = %d\n",tmp);
}
else if(flaga== && flagb==){
printf("? + ");
cout<<b;
printf(" = ?\n");
}
else if(flaga== && flagb==){
printf("%s + ? = ?\n",a);
}
else if(flaga== && flagb==){
printf("? + ? = ?\n");
}
return ;
}
L1-026 I Love GPLT (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805108934557696
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f; int main(){
printf("I\n \nL\no\nv\ne\n \nG\nP\nL\nT\n");
return ;
}
L1-027 出租 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805107638517760
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
char s[];
int vis[],arr[],kk[]; int main(){
scanf("%s",s);
int len=strlen(s);
for(int i=;i<len;i++){
vis[s[i]-'']=;
}
int cnt=;
for(int i=;i>=;i--){
if(vis[i]==) arr[cnt++]=i;
}
for(int i=;i<len;i++){
for(int j=;j<cnt;j++){
if((s[i]-'')==arr[j]) kk[i]=j;
}
}
printf("int[] arr = new int[]{");
for(int i=;i<cnt-;i++){
printf("%d,",arr[i]);
}
printf("%d};\n",arr[cnt-]);
printf("int[] index = new int[]{");
for(int i=;i<len-;i++){
printf("%d,",kk[i]);
}
printf("%d};\n",kk[len-]);
return ;
}
L1-028 判断素数 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805106325700608
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n,x; int main(){
scanf("%d",&n);
while(n--){
scanf("%d",&x);
int flag=;
for(int i=;i<=sqrt(x);i++){
if(x%i==){
flag=;
break;
}
}
if(x==) printf("No\n");
else if(x==) printf("Yes\n");
else if(flag==) printf("No\n");
else if(flag==) printf("Yes\n");
}
return ;
}
L1-029 是不是太胖了 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805104983523328
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
double m=((double)n-)*0.9*;
printf("%.1f\n",m);
return ;
}
L1-030 一帮一 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805103557459968
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n;
int vis[maxn],id[maxn];
char s[maxn][]; struct node{
string s1,s2;
}kk[maxn]; int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d %s",&id[i],s[i]);
}
int cnt=;
for(int i=;i<n;i++){
for(int j=n-;j>=;j--){
if(id[i]!=id[j] && vis[i]== && vis[j]==){
printf("%s %s\n",s[i],s[j]);
vis[i]=;vis[j]=;
}
}
}
return ;
}
L1-031 到底是不是太胖了 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805102173339648
代码:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n,x,y; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&x,&y);
int m=(x-)*1.8;
//printf("%d\n",m);
if(abs(m-y)<(m*0.1)) printf("You are wan mei!\n");
if(abs(m-y)>=(m*0.1) && y<m) printf("You are tai shou le!\n");
if(abs(m-y)>=(m*0.1) && y>m) printf("You are tai pang le!\n");
}
return ;
}
L1-032 Left-pad (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805100684361728
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n;
char x,s[maxn]; int main(){
scanf("%d %c",&n,&x);
getchar();
cin.get(s,);
int len=strlen(s);
if(len>=n){
for(int i=len-n;i<len;i++){
cout<<s[i];
}
cout<<endl;
}
else{
for(int i=;i<n-len;i++){
cout<<x;
}
cout<<s<<endl;
}
return ;
}
L1-033 出生年 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805099426070528
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int x,k; int main(){
scanf("%d%d",&x,&k);
int flag=;
for(int i=x;i<=;i++){
int cnt=;
int a=i/;
int b=i%/;
int c=i%/;
int d=i%;
if(a!=b && a!=c && a!=d) cnt++;
if(b!=c && b!=d) cnt++;
if(c!=d) cnt++;
if(cnt==k){
flag=i;
break;
}
}
printf("%d %04d\n",flag-x,flag);
return ;
}
L1-034 点赞 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805098188750848
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
int n,k,x;
int ans[maxn]; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&k);
for(int j=;j<=k;j++){
scanf("%d",&x);
ans[x]++;
}
}
int mmax=-,pos=-;
for(int i=;i<=;i++){
if(ans[i]>=mmax){
mmax=ans[i];
pos=i;
}
}
printf("%d %d\n",pos,mmax);
return ;
}
L1-035 情人节 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805097018540032
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
string s[maxn]; int main(){
int cnt=;
while(cin>>s[++cnt] && s[cnt][]!='.');
if(cnt>=){
cout<<s[]<<" and "<<s[];
printf(" are inviting you to dinner...\n");
}
else if(cnt>= && cnt<){
cout<<s[];
printf(" is the only one for you...\n");
}
else if(cnt<=) printf("Momo... No one is for you ...\n");
return ;
}
L1-036 A乘以B (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805095676362752
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n,m; int main(){
scanf("%d%d",&n,&m);
printf("%d\n",n*m);
return ;
}
L1-037 A除以B (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805094485180416
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n,m; int main(){
scanf("%d%d",&n,&m);
if(m==){
printf("%d/%d=Error\n",n,m);
return ;
}
double ans=(double)n/(double)m;
printf("%d/",n);
if(m<) printf("(%d)",m);
else printf("%d",m);
printf("=%.2f\n",ans);
return ;
}
L1-038 新世界 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805093038145536
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f; int main(){
printf("Hello World\nHello New World\n");
return ;
}
L1-039 古风排版 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805091888906240
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n;
char s[maxn],ans[maxn][maxn]; int main(){
scanf("%d\n",&n);
cin.getline(s,);
int len=strlen(s);
int tmp=len/n+(len%n==?:);
int cnt=;
for(int i=;i<tmp;i++){
for(int j=;j<n;j++){
if(cnt<len) ans[i][j]=s[cnt++];
else ans[i][j]=' ';
}
}
for(int j=;j<n;j++){
for(int i=tmp-;i>=;i--){
putchar(ans[i][j]);
}
putchar('\n');
}
return ;
}
L1-040 最佳情侣身高差 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805090748055552
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int t;double n;char op[]; int main(){
scanf("%d",&t);
for(int i=;i<=t;i++){
scanf("%s %lf",op,&n);
if(op[]=='M'){
double ans=n/1.09;
printf("%.2f\n",ans);
}
if(op[]=='F'){
double ans=n*1.09;
printf("%.2f\n",ans);
}
}
return ;
}
L1-041 寻找250 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805089657536512
代码:
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int x; int main(){
int cnt=,vis=;
while(scanf("%d",&x)!=EOF){
cnt++;
if(x== && vis==){
printf("%d\n",cnt);
vis=;
}
}
return ;
}
L1-042 日期格式化 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805088529268736
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int m,d,y; int main(){
scanf("%d-%d-%d",&m,&d,&y);
printf("%d-%02d-%02d\n",y,m,d);
return ;
}
L1-043 阅览室 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805087447138304
思路:注意一些只有S或只有E的操作
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n,id,h,m;
int ans[maxn],vis[maxn];
char op[]; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
int cnt=;
double sum=;
id=-;
memset(vis,,sizeof(vis));
while(id!=){
scanf("%d %s %d:%d",&id,op,&h,&m);
if(id==) break;
if(op[]=='S'){
ans[id]=h*+m;
vis[id]=;
}
if(op[]=='E'){
if(vis[id]==){
sum+=h*+m-ans[id];
ans[id]=;
vis[id]=;
cnt++;
}
}
}
if(cnt!=) sum/=cnt;
sum+=0.5f;
printf("%d %d\n",cnt,(int)sum);
}
return ;
}
L1-044 稳赢 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805086365007872
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int k;char s[]; int main(){
scanf("%d",&k);
int cnt=;
k++;
while(scanf("%s",s)!=EOF && s[]!='E'){
cnt++;
if(s[]=='C' && cnt%k!=) printf("Bu\n");
if(s[]=='C' && cnt%k==) printf("ChuiZi\n");
if(s[]=='J' && cnt%k!=) printf("ChuiZi\n");
if(s[]=='J' && cnt%k==) printf("JianDao\n");
if(s[]=='B' && cnt%k!=) printf("JianDao\n");
if(s[]=='B' && cnt%k==) printf("Bu\n");
}
return ;
}
L1-045 宇宙无敌大招呼 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805085295460352
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
char s[]; int main(){
scanf("%s",s);
printf("Hello %s\n",s);
return ;
}
L1-046 整除光棍 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805084284633088
思路:模拟竖式除法
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n; int main(){
scanf("%d",&n);
int x=,cnt=;
while(x<n){
x=x*+;
cnt++;
}
while(x!=){
printf("%d",x/n);
x=x%n;
if(x==) break;
x=x*+;
cnt++;
}
printf(" %d\n",cnt);
return ;
}
L1-047 装睡 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805083282194432
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int n,x,y;
char s[]; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s%d%d",s,&x,&y);
if(x< || x> || y< || y>) printf("%s\n",s);
}
return ;
}
L1-048 矩阵A乘以B (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805082313310208
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int r1,r2,c1,c2;
int ans1[maxn][maxn],ans2[maxn][maxn],ans[maxn][maxn]; int main(){
scanf("%d%d",&r1,&c1);
for(int i=;i<=r1;i++){
for(int j=;j<=c1;j++){
scanf("%d",&ans1[i][j]);
}
}
scanf("%d%d",&r2,&c2);
for(int i=;i<=r2;i++){
for(int j=;j<=c2;j++){
scanf("%d",&ans2[i][j]);
}
}
if(r2!=c1){
printf("Error: %d != %d\n",c1,r2);
return ;
}
memset(ans,,sizeof(ans));
for(int i=;i<=r1;i++){
for(int j=;j<=c2;j++){
for(int k=;k<=c1;k++){
ans[i][j]+=ans1[i][k]*ans2[k][j];
}
}
}
printf("%d %d\n",r1,c2);
for(int i=;i<=r1;i++){
for(int j=;j<c2;j++){
printf("%d ",ans[i][j]);
}
printf("%d\n",ans[i][c2]);
}
return ;
}
L1-049 天梯赛座位分配 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805081289900032
思路:最开始要把所有位置都初始化为-1 这样在只有一个学校的情况下不会出错
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n,cnt[maxn],vis[maxn]; struct node{
int res;
int ans[maxn];
}kk[maxn]; int main(){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++){
scanf("%d",&kk[i].res);
sum+=kk[i].res;
}
sum*=;
int tmp=n;
for(int i=;i<=n;i++) kk[i].ans[]=-;
memset(cnt,,sizeof(cnt));
memset(vis,,sizeof(vis));
for(int i=;i<=sum;){
for(int j=;j<=n;j++){
if(vis[j]==) continue;
if(tmp==){
kk[j].ans[++cnt[j]]=max(kk[j].ans[cnt[j]-]+,i);
i++;
}
else kk[j].ans[++cnt[j]]=i++;
if(cnt[j]/==kk[j].res && cnt[j]%==){
vis[j]=;tmp--;
}
}
}
for(int i=;i<=n;i++){
printf("#%d\n",i);
for(int j=;j<=*kk[i].res;j++){
printf("%d",kk[i].ans[j]);
if(j%==) printf("\n");
else printf(" ");
}
}
return ;
}
L1-050 倒数第N个字符串 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805080346181632
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const char s[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
const int maxn=1e5+;
int n,k;
char ans[]={'z'}; int main(){
scanf("%d%d",&n,&k);
int a,b=k;
for(int i=;i<=n;i++){
a=b%;
b=k/;
k=b;
if(i==){
if(a==){
ans[n-i]=s[];
b--;
}
else ans[n-i]=s[-a];
}
else ans[n-i]=s[-a-];
}
printf("%s\n",ans);
return ;
}
L1-051 打折 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805079364714496
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
double x,y; int main(){
scanf("%lf%lf",&x,&y);
printf("%.2f\n",x/*y);
return ;
}
L1-052 2018我们要赢 (5 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805078400024576
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f; int main(){
printf("2018\nwo3 men2 yao4 ying2 !\n");
return ;
}
L1-053 电子汪 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805077443723264
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int a,b; int main(){
scanf("%d%d",&a,&b);
int m=a+b;
for(int i=;i<=m;i++){
printf("Wang!");
}
printf("\n");
return ;
}
L1-054 福到了 (15 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805076512587776
思路:注意空格和换行 用getchar()读掉换行符 用geline来整行读入(同时读入空格)
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n,vis[maxn][maxn];
char x;
string mp[maxn]; int main(){
scanf("%c %d",&x,&n);
getchar();
for(int i=;i<n;i++){
getline(cin,mp[i]);
for(int j=;j<n;j++){
if(mp[i][j]==' ') vis[i][j]=;
else vis[i][j]=;
}
}
int flag=;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(vis[i][j]!=vis[n-i-][n-j-]) flag=;
}
}
if(flag==){
printf("bu yong dao le\n");
}
for(int i=n-;i>=;i--){
for(int j=n-;j>=;j--){
if(vis[i][j]==) cout<<" ";
else if(vis[i][j]==) cout<<x;
}
cout<<endl;
}
return ;
}
L1-055 谁是赢家 (10 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805075543703552
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
int a,b,ansa,ansb,x; int main(){
scanf("%d%d",&a,&b);
ansa=,ansb=;
for(int i=;i<=;i++){
scanf("%d",&x);
if(x==) ansa++;
else ansb++;
}
if(a>b && ansa>=) printf("The winner is a: %d + %d\n",a,ansa);
else if(a<b && ansa==) printf("The winner is a: %d + %d\n",a,ansa);
else printf("The winner is b: %d + %d\n",b,ansb);
return ;
}
L1-056 猜数字 (20 分)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805074646122496
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=1e4+;
int n,x[maxn];
char s[maxn][]; int main(){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++){
scanf("%s %d",s[i],&x[i]);
sum+=x[i];
}
sum/=(n*);
int minn=inf,pos=;
for(int i=;i<=n;i++){
if(abs(sum-x[i])<minn){
minn=abs(sum-x[i]);
pos=i;
}
}
printf("%d %s\n",sum,s[pos]);
return ;
}