自测-1 打印沙漏 (20分)
https://pintia.cn/problem-sets/17/problems/260
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 using namespace std; 6 int n; 7 int choice(int n){ 8 for(int i=1;i<=23;i++){ 9 if((2*i*i-1<=n)&&(2*(i+1)*(i+1)-1>n)) 10 return i; 11 } 12 } 13 int main(){ 14 char chr; 15 cin>>n>>chr; 16 int i=choice(n); 17 int empty=0,c=2*i-1; 18 for(int j=1;j<=2*i-1;j++){ 19 for(int k=0;k<empty;k++) cout<<" "; 20 for(int k=0;k<c;k++) cout<<chr; 21 cout<<endl; 22 if(j<i){ 23 empty+=1; 24 c-=2; 25 } 26 else if(j>=i){ 27 empty-=1; 28 c+=2; 29 } 30 } 31 cout<<n-2*i*i+1<<endl; 32 return 0; 33 }
自测-2 素数对猜想 (20分)
https://pintia.cn/problem-sets/17/problems/261
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 bool is_prime(int n){ 7 int i; 8 for(i=2;i<=(int)(sqrt(n)+0.5);i++){ 9 if(n%i==0) break; 10 } 11 if(i>(int)(sqrt(n)+0.5)) return true; 12 else return false; 13 } 14 int main(){ 15 int n;cin>>n; 16 int count=0,value1=2,value2=3; 17 while(value2<=n){ 18 if(is_prime(value2)){ 19 if(value2-value1==2) count++; 20 value1=value2; 21 } 22 value2++; 23 } 24 cout<<count<<endl; 25 return 0; 26 }
自测-3 数组元素循环右移问题 (20分)
https://pintia.cn/problem-sets/17/problems/262
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 int main(){ 7 int n,m,a[102],value; 8 cin>>n>>m; 9 for(int i=0;i<n;i++) cin>>a[i]; 10 m=m%n; 11 for(int i=n-m;i<n;i++) cout<<a[i]<<" "; 12 for(int i=0;i<n-m;i++) { 13 if(i!=n-m-1) cout<<a[i]<<" "; 14 else cout<<a[i]; 15 } 16 return 0; 17 }
自测-4 Have Fun with Numbers (20分)
https://pintia.cn/problem-sets/17/problems/263
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <cmath> 5 #include <algorithm> 6 #include <iostream> 7 using namespace std; 8 char chr1[22]; 9 int num1[25]={0},num2[25]={0},a[10]={0},b[10]={0}; 10 int main(){ 11 int i=0,j=0,k=0; 12 cin>>chr1; 13 int len1=strlen(chr1); 14 for(int i=0;i<len1;i++) a[chr1[i]-'0']++; 15 for(i=len1-1;i>=0;i--) num1[j++]=chr1[i]-'0'; 16 int m=0; 17 for(i=0;i<len1;i++){ 18 num2[i]+=num1[i]*2%10; 19 m=num1[i]*2/10; 20 num2[i+1]+=m; 21 } 22 bool flag=true,flag1=true; 23 for(i=24;i>=0;i--){ 24 if(num2[i]!=0) flag=false; 25 if(!flag){ 26 //if(a[num2[i]]==0) {flag1=false;break;} 27 //else if(a[num2[i]]!=0) a[num2[i]]--; 28 b[num2[i]]++; 29 } 30 } 31 32 for(int i=0;i<10;i++) 33 if(a[i]!=b[i]) {flag1=false;break;} 34 35 flag=true; 36 if(flag1==false) cout<<"No "; 37 else if(flag1) cout<<"Yes "; 38 for(i=24;i>=0;i--){ 39 if(num2[i]!=0) flag=false; 40 if(!flag) cout<<num2[i]; 41 } 42 cout<<endl; 43 return 0; 44 }
自测-5 Shuffling Machine (20分)
https://pintia.cn/problem-sets/17/problems/264
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <cmath> 6 #include <algorithm> 7 using namespace std; 8 char *str[22][54]={"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","H1","H2","H3","H4","H5","H6","H7","H8","H9","H10","H11","H12","H13","C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13","D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","D11","D12","D13","J1","J2"}; 9 10 int a[54]; 11 int main(){ 12 int k;cin>>k; 13 for(int i=0;i<54;i++) cin>>a[i]; 14 for(int i=1;i<=k;i++){ 15 for(int j=0;j<54;j++){ 16 str[i][a[j]-1]=str[i-1][j]; 17 } 18 } 19 for(int i=0;i<54;i++){ 20 if(i!=53) cout<<str[k][i]<<" "; 21 else cout<<str[k][i]; 22 } 23 return 0; 24 }