公司动态
天梯赛选拔赛2补题
--记忆数字字符串的遍历错误代码混乱专门用来遍历一个字符串 / 数组 / 容器里的每一个元素for (char ch : str)1.cin str读到空格就停止读不进带空格的句子比如输入hello world只能读到hello2.getline(cin, str)读到回车才停能读一整行包括空格比如输入I love coding 123 !!!能完整读进去#includebits/stdc.h char ch; using namespace std; int main() { string str; getline(cin,str); //能读一整行包括空格 int l0; for(int i0;istr.size();i) { if(isalpha(str[i]))//遍历判断是不是字母 l; else if(l!0) // 遇到非字母且前面有字母 //如果现在的字符不是字母并且长度l不等于零就输出 { coutl%10; l0; } } if(l!0) //该条件触发的前提是后面不是字母 // hello world其中world后面没有非字母 遍历过后只出现 5 不是55 { coutl%10; //保证去个位数 } return 0; }--预测帕鲁向下取整链接https://ac.nowcoder.com/acm/contest/131017/E来源牛客网错误代码上取整写错为下取整#includeiostream #includeclimits #includestring #includecstdio using namespace std; int n; int a[505]; int x,y,av; int c; int minsINT_MAX; int main() { scanf(%d,n); for(int i1;in;i) { scanf(%d,a[i]); } scanf(%d %d,x,y); av(a[x]a[y])/2; for(int j1;jn;j) { if(abs(av-a[j])mins) { minsabs(av-a[j]); cj; } } printf(%d\n,c); return 0; }#includeiostream #includeclimits #includestring #includecstdio using namespace std; int n; int a[505]; int x,y,av; int c; int minsINT_MAX; int main() { scanf(%d,n); for(int i1;in;i) { scanf(%d,a[i]); } scanf(%d %d,x,y); av(a[x]a[y]1)/2; for(int j1;jn;j) { if(abs(av-a[j])mins) { minsabs(av-a[j]); cj; } } printf(%d\n,c); return 0; }F统一命名规范链接https://ac.nowcoder.com/acm/contest/131017/F来源牛客网理解错题意了 也没抓到准确关键点 忽略了“只会存在以下三种命名规范”写出的代码太乱了 太长#include bits/stdc.h #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef long long ll; #define endl \n; using namespace std; int main() { IOS ll n; string op; string s; string ans; cinnop; if(opCamel) { for(ll i1;in;i) { cins; ans; anstolower(s[0]); bool okfalse; for(ll j1;js.size();j) { if(ok) { anstoupper(s[j]); okfalse; } else if(!isalpha(s[j])) { oktrue; } else { anss[j]; } } coutansendl; } } else if(opPascal) { for(ll i1;in;i) { cins; ans; anstoupper(s[0]); bool okfalse; for(ll j1;js.size();j) { if(ok) { anstoupper(s[j]); okfalse; } else if(!isalpha(s[j])) { oktrue; } else { anss[j]; } } coutansendl; } } else { for(ll i1;in;i) { cins; ans; anstolower(s[0]); bool okfalse; for(ll j1;js.size();j) { if(s[j]As[j]Z) { ans_; anstolower(s[j]); } else { anss[j]; } } coutansendl; } } return 0; }