2025一开始思路比较复杂,还想着把“(max)”插入字符串,然后就“烫烫烫”了,后面看了大佬们的答案,原来还有这么简单的方法,可恨我咋就没想到
#include
#include
using namespace std;
int main()
{
string s;
while (cin >> s)
{
char ch[100];
strcpy(ch, s.c_str());
int len = s.length();
char max=ch[0];
for (int i = 0; i < len; i++)
{
if (ch[i] > max)
max = ch[i];
}
for (int i = 0; i < len; i++)
{
cout << ch[i];
if (ch[i] == max)
cout << "(max)";
}
cout << endl;
}
return 0;
}
2026.
#include
#include
using namespace std;
int main()
{
char ch[100];
string s;
while (gets(ch))
{
//strcpy(ch, s.c_str());
int len = strlen(ch);
for (int i = 0; i < len; i++)
{
if (i == 0 || ch[i - 1] == ' ')
{
ch[i] -= 32;
}
}
cout <
return 0;
}
有个疑问:为什么这样写就会每个单词后面都输出了回车
#include
#include
using namespace std;
int main()
{
string s;
while (cin >> s)
{
char ch[100];
strcpy(ch, s.c_str());
int len = s.length();
for (int i = 0; i < len; i++)
{
if (i == 0 || ch[i - 1] == ' ')
{
ch[i] -= 32;
}
}
cout <
return 0;
}
2027
#include
#include
using namespace std;
int main()
{
int n;
char str[100];
int na, ne, ni, no, nu;
while (cin >> n)
{
getchar();//很关键,用来跳过回车字符
while (n--)
{
gets(str);
int len = strlen(str);
na = ne = ni = no = nu = 0;
for (int i = 0; i < len; i++)
{
char x = str[i];
switch (x)
{
case 'a':na++;
break;
case'e':ne++;
break;
case'i':ni++;
break;
case'o':no++;
break;
case'u':nu++;
break;
default:
break;
}
}
if (n == 0)
cout << "a:" << na << endl << "e:" << ne << endl << "i:" << ni << endl << "o:" << no << endl << "u:" << nu<
cout << "a:" << na << endl << "e:" << ne << endl << "i:" << ni << endl << "o:" << no << endl << "u:" << nu << endl << endl;
}
}
return 0;
}
2028。
这个方法不知为啥没过,还是记录一下
#include
#include
using namespace std;
int gongyue(long a,long b)
{
if (a%b == 0)
return b;
else return gongyue(b,a%b);
}
int main()
{
int n;
long a, b;
while (cin >> n)
{
cin >> a;
if (n == 1)
{
cout << a << endl;
continue;
}
for (int i = 1; i < n; i++)
{
cin >> b;
a = a*b / gongyue(a, b);
}
cout << a<
return 0;
}
ac代码:
#include
#include
using namespace std;
int gongyue(long a, long b)
{
return b==0? a:gongyue(b, a%b);
}
int main()
{
int n;
int a, b,c;
while (cin >> n)
{
cin >> a;
if (n == 1)
{
cout << a << endl;
continue;
}
for (int i = 1; i < n; i++)
{
cin >> b;
c = gongyue(a, b);
a = a/ c*b ;
}
cout << a << endl;
}
return 0;
}
然后发现应该先除再乘
2029
#include
#include
using namespace std;
int main()
{
int n;
char ch[100];
while (cin >> n)
{
getchar();
bool flag ;
while (n--)
{
gets(ch);
int len = strlen(ch);
flag = true;
for (int i = 0; i < len; i++)
{
if (ch[i] != ch[len - i - 1])
flag = false;
}
if (flag)
{
cout << "yes" << endl;
}
else cout << "no" << endl;
}
}
return 0;
}