#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
char get(int x) // 将x转化为b进制
{
if(x <= 9) return x + '0';
return x - 10 + 'A';
}
string base(int n, int b) // n 在 b 进制下的表示
{
string num;
while(n) num += get(n % b), n /= b;
reverse(num.begin(), num.end());
return num;
}
bool check(string num)
{
for(int i = 0, j = num.size() - 1; i < j; i ++, j -- )
if(num[i] != num[j])
return false;
return true;
}
int main()
{
int b;
cin >> b;
for(int i = 1; i <= 300; i ++ )
{
string num = base(i * i, b);
if(check(num))
cout << base(i, b) << ' ' << num << endl;
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1e5 + 10;
int w[N];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i ++ ) scanf("%d", &w[i]);
sort(w, w + n);
for(int i = 0, j = n - 1; i < j; i ++ )
{
while(i < j && w[i] + w[j] > m) j -- ;
if(i < j && w[i] + w[j] == m)
{
printf("%d %d\n", w[i], w[j]);
return 0;
}
}
puts("No Solution");
return 0;
}
作者:Once.
链接:https://www.acwing.com/activity/content/code/content/3388601/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
int main()
{
string str;
getline(cin, str);
map<string, int> hash;
for(int i = 0; i < str.size(); i ++ )
{
if(isalpha(str[i]))
{
int j = i;
string word;
while(j < str.size() && isalpha(str[j]))
word += tolower(str[j ++ ]);
hash[word] ++ ;
i = j - 1;
}
}
for(auto &c : hash)
{
cout << c.first << ':' << c.second << endl;
}
return 0;
}
作者:Once.
链接:https://www.acwing.com/activity/content/code/content/3106636/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。