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-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\n",i-y,i); 21 break; 22 } 23 } 24 return 0; 25 }
原文地址:https://www.cnblogs.com/jianqiao123/p/12115478.html
时间: 2024-11-08 21:53:40