나만의Astro✨돼줘. level
获赞
146
粉丝
1
关注
4
看过 TA
1
吉林大学
2018
算法工程师
IP属地:北京
暂未填写个人简介
私信
关注
2017-09-14 21:46
已编辑
吉林大学 算法工程师
C++  渣渣一只。 艾玛编程有点简单啊。第二题居然一次过。 一会过了考试时间发代码大神可以交流交流咩。
나만의Astro✨돼줘.:/*#include <iostream> #include <cmath> #include <string> #include <set> #include <string.h> #include <algorithm> #include <vector> #include <map> #include <stack> #include <queue> #define MAXX (10000) using namespace std; int main() { int n; int getD(int); int dd[11]; dd[0] = 1; for (int i = 1; i <11; i++) { dd[i] = (dd[i - 1] * 10) % 7; } while (cin >> n) { vector<int> v; for (int i = 0; i < n; i++) { int t; cin >> t; v.push_back(t); } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; int temp = 0; temp = temp+(v[i] % 7)*dd[getD(v[j])]; temp %= 7; temp = (temp + v[j]) % 7; if (temp == 0) count += 1; } } cout << count << endl; } } int getD(int n) { if (n <= 9) return 1; int i = 0; while (n != 0) { i += 1; n /= 10; } return i; } ----------------------------------上面是O(n^2)解法-------------------------------------- ----------------------------------下面是O(n)解法----------------------------------------*/ #include <iostream> #include <cmath> #include <string> #include <set> #include <string.h> #include <algorithm> #include <vector> #include <map> #include <stack> #include <queue> #define MAXX (10000) using namespace std; int main() { int n; int getD(int);//这个数几位数 int dd[11]; //dd[i]=(10^i)%7 dd[0] = 1; for (int i = 1; i <11; i++) { dd[i] = (dd[i - 1] * 10) % 7; } int tongyujie[7] = { 0,1,4,5,2,3,6 }; //tongyujie[i]*i=0(mod 7) while (cin >> n) { int s0 = 0, s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0, s6 = 0;//sn表示除7余n数的个数 vector<int> v; for (int i = 0; i < n; i++) { int t; cin >> t; v.push_back(t); switch (t % 7) { case 0:s0 += 1; break; case 1:s1 += 1; break; case 2:s2 += 1; break; case 3:s3 += 1; break; case 4:s4 += 1; break; case 5:s5 += 1; break; case 6:s6 += 1; break; default:; } } int count = 0; for (int i = 0; i < n; i++) { int yushu = v[i] % 7; int temp = ((7 - yushu)*tongyujie[dd[getD(v[i])]]) % 7; //std::cout <<endl<< yushu << " " << temp << endl; if (yushu == temp) count -= 1;//自身和自身不能同时取到 switch (temp) { case 0:count += s0; break; case 1:count += s1; break; case 2:count += s2; break; case 3:count += s3; break; case 4:count += s4; break; case 5:count += s5; break; case 6:count += s6; break; default:; } } std::cout << count << endl; } } int getD(int n) { if (n <= 9) return 1; int i = 0; while (n != 0) { i += 1; n /= 10; } return i; }
投递美团等公司10个岗位 >
0 点赞 评论 收藏
分享
关注他的用户也关注了:
牛客网
牛客企业服务