第一题:
代码:
#include<stdio.h>
int main()
{
int N=0;
scanf("%d",&N);
printf("L");
for(int i=0;i<N;i++){
printf("o");
}
printf("ng");
return 0;
}
思路:
用C语言解决,根据题目需求,用一个for循环printf出需要的数量的'o'即可,剩下部分依次输出。
第二题:
代码:
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
int main()
{
int t;
std::cin >> t;
while (t--) {
std::string s;
std::cin >> s;
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
if (s == "yes") {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}
}
return 0;
}
思路:
需求为任意形式的"YES",那么不妨考虑将所有输入的字母都转化为小写,将其与“yes“比较,以此判断是否符合要求。这里用到一个transform函数,接受输入范围的开始和结束迭代器、输出范围的开始迭代器,以及一元操作函数::tolower来实现全部转化为小写的目的。
第三题:
代码:
#include<iostream>
#include <string.h>
using namespace std;
int main()
{
int n;
cin>>n;
char s[61];
for(int i=0;i<n;i++)
{
cin>>