L1-050 倒数第N个字符串 (15分)
https://pintia.cn/problem-sets/994805046380707840/problems/994805080346181632
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <iostream> 5 #include <cmath> 6 using namespace std; 7 int f(int l) 8 { 9 int sum=1; 10 for(int i=0;i<l;i++) sum*=26; 11 return sum; 12 } 13 int main() 14 { 15 int l,n; 16 int i,j,k; 17 char a[10]; 18 cin>>l>>n; 19 int x=f(l)-n; 20 k=0; 21 for(j=l-1;j>=0;j--) 22 { 23 a[k]=x/f(j)+'a'; 24 x=x%f(j); 25 k++; 26 } 27 for(j=0;j<l;j++) cout<<a[j]; 28 cout<<endl; 29 return 0; 30 }
L1-043 阅览室 (20分)
https://pintia.cn/problem-sets/994805046380707840/problems/994805087447138304
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #include <cstring> 5 #include <string> 6 #include <cmath> 7 using namespace std; 8 int main() 9 { 10 int n; 11 cin>>n; 12 while(n--) 13 { 14 int num,hour,minute; 15 char chr; 16 int vis[1005]={0}; 17 int inter[1005]; 18 int con=0,sum=0; 19 while(~scanf("%d %c %d:%d",&num,&chr,&hour,&minute)&&num) //若没写&chr,只写了chr的话会报超时错误 20 { 21 if(chr=='S') 22 { 23 vis[num]=1; 24 inter[num]=hour*60+minute; 25 } 26 else if(chr=='E'&&vis[num]) 27 { 28 vis[num]=0; 29 con++; 30 sum+=(60*hour+minute-inter[num]); 31 } 32 } 33 if(con==0) cout<<"0 0 "; 34 else cout<<con<<" "<<(int)(sum*1.0/con+0.5)<<endl; 35 } 36 return 0; 37 }
L1-046 整除光棍 (20分)
https://pintia.cn/problem-sets/994805046380707840/problems/994805084284633088
(ps:躺床上想出来的)
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cmath> 5 #include <cstring> 6 #include <string> 7 typedef long long ll; 8 using namespace std; 9 int main() 10 { 11 int x,i=0; 12 int a[1000]={0}; 13 cin>>x; 14 ll sum=1; 15 int count=1; 16 while(sum<x) 17 { 18 sum=sum*10+1; 19 count++; 20 } 21 while(sum%x!=0) 22 { 23 a[i]=sum/x; 24 sum=sum%x*10+1; 25 i++; 26 count++; 27 } 28 if(sum%x==0) a[i]=sum/x; 29 for(int j=0;j<=i;j++) cout<<a[j]; 30 cout<<" "<<count<<endl; 31 return 0; 32 }
L1-006 连续因子 (20分)
https://pintia.cn/problem-sets/994805046380707840/problems/994805138600869888
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 typedef long long ll; 8 int main() 9 { 10 ll n,m,i,j,k=-1,a,b; 11 cin>>n; 12 m=(ll)sqrt(n); 13 b=n; 14 for(i=2;i<=m;i++) 15 { 16 if(n%i!=0) continue; 17 a=1; 18 for(j=i;j<=m;j++) 19 { 20 if(n%(a*j)!=0||(a*j)>n) break; 21 a*=j; 22 } 23 if(j-i>k) { 24 k=j-i; 25 b=i; 26 } 27 } 28 if(k==-1) k=1; 29 cout<<k<<endl; 30 cout<<b; 31 for(i=b+1;i<b+k;i++) cout<<"*"<<i; 32 cout<<endl; 33 return 0; 34 }
L1-033 出生年 (15分)
https://pintia.cn/problem-sets/994805046380707840/problems/994805099426070528
set容器使用:https://blog.csdn.net/strawberry_595/article/details/81188509
1 #include <cstdio> 2 #include <iostream> 3 #include <set> 4 using namespace std; 5 int main() 6 { 7 int y,n; 8 cin>>y>>n; 9 for(int i=y;i<=3012;i++) 10 { 11 set<int> s; 12 int num=i; 13 for(int j=0;j<4;j++) 14 { 15 s.insert(num%10); 16 num/=10; 17 } 18 if(s.size()==n) 19 { 20 printf("%d %04d ",i-y,i); 21 break; 22 } 23 } 24 return 0; 25 }