吉比特笔试8.27
晚上先考京东再考吉比特,上来一堆数学给我搞蒙了
第一题求字符串中给定的两个字母最大距离的绝对值,不知道为什么只有90.我猜可能有输入特殊字符?
//字符最大距离 #include<iostream> #include<cstdlib> #include<vector> #include<algorithm> #include<cstring> using namespace std; int main() { string s; char a; char b; cin >> s; cin >> a; cin >> b; int i; int flag1; for (i = 0; i < s.length(); i++) { if (s[i] == a || a + 32 == s[i] || a - 32 == s[i]) { flag1 = i; break; } } if (i == s.length()) { cout << -1; return 0; } for (i = s.length() - 1; i >= 0; i--) { if (s[i] == b || b + 32 == s[i] || b - 32 == s[i]) break; } if (i == -1) { cout << -1; return 0; } cout << abs(i - flag1); return 0; } 第二题 无尽虚空什么什么的,就是前一天的XYZ可以分别生成另外两种 //无尽的世界 #include<iostream> #include<cstdlib> #include<vector> #include<algorithm> #include<cstring> using namespace std; int main() { long long x; long long y; long long z; long n; int xa, ya, xb, yb, xc, yc; cin >> x >> y >> z >> n >> xa >> ya >> xb >> yb >> xc >> yc; int i = 0; long long prex; long long prey; long long prez; for (i = 0; i <= n; i++) { if (i == 0) { prex = x; prey = y; prez = z; } else { x = (prex + prey * xb + prez * xc) % 1000000007; y = (prey + prex * xa + prez * yc) % 1000000007; z = (prez + prex * ya + prey * yb) % 1000000007; prex = x; prey = y; prez = z; } } cout << x << " " << y << " " << z; return 0; }只有70,超时了果然还是太菜了😪