标签:倒序 space vector 16px cto end 遍历 back 时间
1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5 int main() 6 { 7 int a; 8 int b; 9 vector<int> wei1;//倒序存储每一位 10 vector<int> wei;//正序存储每一位 11 int tmp; 12 int result1 = 0; 13 int result2 = 0; 14 while(cin>>a>>b) 15 { 16 int count=0; 17 int num = 0; 18 if(b <= 10) 19 cout<<count<<endl; 20 else 21 { 22 if(a<=10) 23 a = 11; 24 for(int i=a;i<=b;i++) 25 { 26 num=0; 27 tmp = i; 28 while(tmp) 29 { 30 wei1.push_back(tmp%10); 31 tmp = tmp/10; 32 } 33 for(int x=wei1.size()-1;x>=0;x--) 34 { 35 wei.push_back(wei1[x]); 36 } 37 38 39 for(int k=0;k<wei.size();k++) 40 { 41 for(int z=k+1;z<wei.size();z++) 42 { 43 num = 0;//此处别忘了num置0 44 result1 = wei[k]*10+wei[z]; 45 result2 = wei[z]*10+wei[k]; 46 //判断result是否为质数 47 if(result1/10 == 0) 48 { 49 result1 = 0; 50 num++; 51 } 52 53 for(int j=2;j<result1;j++) 54 { 55 if(result1%j==0) 56 { 57 num++; 58 } 59 } 60 if(num == 0) 61 { 62 break; 63 } 64 65 else 66 { 67 num = 0; 68 if(result2/10 == 0) 69 { 70 result2 = 0; 71 num++; 72 } 73 74 for(int j=2;j<result2;j++) 75 { 76 if(result2%j==0) 77 { 78 num++; 79 break; 80 } 81 } 82 if(num == 0) 83 { 84 break; 85 } 86 } 87 } 88 89 if(num == 0) 90 { 91 count++; 92 break; 93 } 94 } 95 wei.clear(); 96 wei1.clear(); 97 } 98 } 99 cout<<count<<endl; 100 } 101 }
标签:倒序 space vector 16px cto end 遍历 back 时间
原文地址:http://www.cnblogs.com/qqky/p/6884656.html