PAT (Basic Level) Practice (中文)1093、1094
2020-01-13 22:56:54
1094 谷歌的招聘 (20分)
https://pintia.cn/problem-sets/994805260223102976/problems/1071785997033074688
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <cstdio> 5 #include <cmath> 6 #include <algorithm> 7 using namespace std; 8 bool is_Prime(int n) 9 { 10 int m=(int)sqrt(n); 11 int i; 12 for(i=2;i<=m;i++) 13 { 14 if(n%i==0) break; 15 } 16 if(i>m) return 1; 17 return 0; 18 } 19 int change_math(char chr[],int i,int k) 20 { 21 int sum=0; 22 int digit=1; 23 for(int j=i+k-1;j>=i;j--) 24 { 25 sum+=(chr[j]-'0')*digit; 26 digit*=10; 27 } 28 return sum; 29 } 30 int main() 31 { 32 int l,k,j,s,i; 33 cin>>l>>k; 34 char chr[1001]; 35 for(i=0;i<l;i++) cin>>chr[i]; 36 for(j=0;j<=l-k;j++) 37 { 38 int sum=change_math(chr,j,k); 39 if(is_Prime(sum)) 40 { 41 for(s=j;s<=j+k-1;s++) cout<<chr[s]; 42 break; 43 } 44 } 45 if(j>l-k) cout<<"404"<<endl; 46 return 0; 47 }
1093 字符串A+B (20分)
https://pintia.cn/problem-sets/994805260223102976/problems/1071785884776722432
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <iostream> 5 #include <cmath> 6 #include <algorithm> 7 using namespace std; 8 int main() 9 { 10 int arr[127]={0}; 11 char chr; 12 int i; 13 for(i=0;i<2;i++) 14 { 15 while((chr=getchar())!='\n') 16 { 17 if(arr[chr]==0) 18 { 19 arr[chr]=1; 20 cout<<chr; 21 } 22 } 23 } 24 cout<<endl; 25 return 0; 26 }
天晴了,起飞吧