#include <stdio.h>
int main() {
int c, q = 1;
while ((c = getchar()) != EOF) {
if (c == '"') {
printf("%s", q ? "``" : "''");
q = !q;
} else
printf("%c", c);
}
return 0;
}
#include <stdio.h>
char s[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
int main() {
int i, c;
while ((c = getchar()) != EOF) {
for (i = 1; s[i] && s[i] != c; i ++ );
if (s[i])
putchar(s[i - 1]);
else
putchar(c);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
const char *rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char *msg[] = {"not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome"};
char r(char ch) {
if (isalpha(ch))
return rev[ch - 'A'];
return rev[ch - '0' + 25];
}
int main() {
char s[30];
while (scanf("%s", s) == 1) {
int len = strlen(s);
int p = 1, m = 1;
for (int i = 0; i < (len + 1) / 2; i ++ ) {
if (s[i] != s[len - 1 - i])
p = 0; // 不是回文串
if (r(s[i]) != s[len - 1 - i])
m = 0; // 不是镜像串
}
printf("%s -- is %s.\n\n", s, msg[m * 2 + p]);
}
return 0;
}
#include <stdio.h>
#define maxn 1010
int main() {
int n, a[maxn], b[maxn];
int kase = 0;
while (scanf("%d", &n) == 1 && n) {
printf("Game %d:\n", ++ kase);
for (int i = 0; i < n; i ++ )
scanf("%d", &a[i]);
for (;;) {
int A = 0, B = 0;
for (int i = 0; i < n; i ++ ) {
scanf("%d", &b[i]);
if (a[i] == b[i])
A ++ ;
}
if (b[0] == 0)
break;
for (int d = 1; d <= 9; d ++ ) {
int c1 = 0, c2 = 0;
for (int i = 0; i < n; i ++ ) {
if (a[i] == d)
c1 ++ ;
if (b[i] == d)
c2 ++ ;
}
if (c1 < c2)
B += c1;
else
B += c2;
}
printf(" (%d,%d)\n", A, B - A);
}
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define maxn 100005
int ans[maxn];
int main() {
int T, n;
memset(ans, 0, sizeof ans);
for (int m = 1; m < maxn; m ++ ) {
int x = m, y = m;
while (x > 0) {
y += x % 10;
x /= 10;
}
if (ans[y] == 0 || m < ans[y])
ans[y] = m;
}
scanf("%d", &T);
while (T -- ) {
scanf("%d", &n);
printf("%d\n", ans[n]);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define maxn 105
int less(const char *s, int p, int q) {
int n = strlen(s);
for (int i = 0; i < n; i ++ )
if (s[(p + i) % n] != s[(q + i) % n])
return s[(p + i) % n] < s[(q + i) % n];
return 0;
}
int main() {
int T;
char s[maxn];
scanf("%d", &T);
while (T -- ) {
scanf("%s", s);
int ans = 0;
int n = strlen(s);
for (int i = 1; i < n; i ++ )
if (less(s, i, ans))
ans = i;
for (int i = 0; i < n; i ++ )
putchar(s[(i + ans) % n]);
putchar('\n');
}
return 0;
}
#include <algorithm>
#include <iostream>
using namespace std;
char str[90];
int score[90];
int main() {
int n;
scanf("%d", &n);
while (n --) {
scanf("%s", str);
score[0] = (str[0] == 'O');
for (int i = 1 ; str[i] ; ++ i) {
score[i] = score[i - 1] + 1;
if (str[i] == 'X')
score[i] = 0;
}
int sum = 0;
for (int i = 0 ; str[i] ; ++ i)
sum += score[i];
printf("%d\n", sum);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
double mass (char c){
switch(c){
case 'C':
return 12.01;
case 'H':
return 1.008;
case 'O':
return 16.00;
case 'N':
return 14.01;
}
}
int main(){
int T;
scanf("%d", &T);
while(T--){
char s[85];
double molar = 0.0;
scanf("%s", s);
double x = 0.0;
int len = strlen(s);
for(int i = 0; i < len; i++){
if(isalpha(s[i])){
x = mass(s[i]);
molar += x;
}
else if(isdigit(s[i])){
int n = s[i] - '0';
if(isdigit(s[i+1])){
n = n*10 + (s[i+1]-'0');
i++;
}
molar += (n-1)*x;
x = 0.0;
}
}
printf("%.3f\n", molar);
}
return 0;
}
#include <bits/stdc++.h> //万能头文件
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
stringstream ss ; //实现整型、字符型的相互转化
int num;
cin >> num;
char a[40000] ;
for (int i = 1; i <= num; i++)
ss << i;
ss >> a ;
int len = strlen(a) ; //字符数组长度,
for (char i = '0'; i <= '9'; i++)
cout << count(a, a + len, i) << (i == '9' ? "\n" : " "); //字符0-9在数组中出现的次数
}
return 0 ;
}
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
int t; cin >> t;
char s[85];
while (t--)
{
memset(s, 0, sizeof(s));
scanf("%s", s);
int len = strlen(s);
int j;
for (int i = 1; i <= len; ++i)
if (len%i == 0)
{
for (j = i; j <= len; j++)
if (s[j] != s[j%i])
break;
if (j == len)
{
cout << i << endl;
break;
}
}
if (t)cout << endl;
}
}
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char puzzle[10][10];
void printPuzzle() {
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 4; ++j)
cout << puzzle[i][j] << ' ';
cout << puzzle[i][4] << endl;
}
}
int main() {
int kase = 0;
while (fgets(puzzle[0], 7, stdin)) { //读入7-1=6个字符,即每行的5个字符加换行
if (puzzle[0][0] == 'Z')
break;
for (int i = 1; i < 5; ++i)
fgets(puzzle[i], 7, stdin);
//cout << "Read Finished" << endl;
//printPuzzle(); //测试读入情况
int ei = 0, ej = 0; //找出空的那个格子
for (int i = 0; i < 5; ++i)
for (int j = 0; j < 5; ++j)
if (puzzle[i][j] == ' ') {
ei = i, ej = j;
break;
}
bool valid = true; //标志非法指令出现过
char moves[101];
int cnt = 0;
char c;
while (cin >> c && c != '0') //考虑隔行读入
moves[cnt++] = c;
int ni = ei, nj = ej;
for (int i = 0; i < cnt; ++i) {
switch (moves[i]) {
case 'A':
ni = ei - 1;
nj = ej;
break;
case 'B':
ni = ei + 1;
nj = ej;
break;
case 'L':
nj = ej - 1;
ni = ei;
break;
case 'R':
nj = ej + 1;
ni = ei;
break;
default:
break;
}
//非法情况:
if (ni < 0 || ni > 4 || nj < 0 || nj > 4) {
valid = false;
break;
} else {
swap(puzzle[ei][ej], puzzle[ni][nj]);
ei = ni, ej = nj; //更新空格位置
}
}
getchar(); //非常重要!吞掉指令结束符0后面的回车!
if (kase++)
cout << endl; //非首个测试前输出换行
cout << "Puzzle #" << kase << ":\n";
if (valid == false)
cout << "This puzzle has no final configuration." << endl;
else
printPuzzle();
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int m,n,u=0;
while((~scanf("%d",&m))&&m)
{
scanf("%d",&n);getchar();
if(u) printf("\n");
char puzzle[m][n+1];
int i,j;
for(i=0;i<m;i++)
for(j=0;j<=n;j++)
puzzle[i][j]=getchar();
int num[m][n],k=0;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(puzzle[i][j]!='*'&&(!i||!j||puzzle[i-1][j]=='*'||puzzle[i][j-1]=='*'))
num[i][j]=++k;
else if(puzzle[i][j]!='*')
num[i][j]=-1;
else
num[i][j]=0;
}
// for(i=0;i<m;i++)
// for(j=0;j<n;j++)
// {
// printf("%d",num[i][j]);
// printf("\n");
// }
printf("puzzle #%d:\n",++u);
printf("Across\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(num[i][j]>0)
{
printf("%3d.",num[i][j]);
for(;j<n&&num[i][j];printf("%c",puzzle[i][j++]));
printf("\n");
}
}
printf("Down\n");
int ii;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(num[i][j]>0)
{
printf("%3d.",num[i][j]);
for(ii=i;ii<m&&num[ii][j];printf("%c",puzzle[ii][j]),num[ii++][j]=0);
printf("\n");
}
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string temp;
vector<string> v; ///存储各个字符串
int n,len,T;
int cnt[26]; ///记录26个英文字母各个所出现的次数
int main(){
cin >> T;
while(T--){
v.clear();
memset(cnt,0,sizeof(cnt));
int sum = 0;
cin >> n >> len;
for(int i = 0;i < n;++i){ ///输入
cin >> temp;
v.push_back(temp);
}
for(int i = 0;i < len;++i){ ///记录每个字母出现的次数
memset(cnt,0,sizeof(cnt));
for(int j = 0;j < n;++j){
char ch = v[j][i];
cnt[ch-'A']++;
}
int ans = (max_element(cnt,cnt+26)-cnt); ///求出出现次数最多字母的下标
printf("%c",ans+'A'); ///输出这个字符
char ch = ans+'A';
for(int j = 0;j < n;++j){ ///累计汉明距离
if(v[j][i]!=ch)
sum++;
}
}
printf("\n");
printf("%d\n",sum);
}
return 0;
}
//#define LOCAL
#include <stdio.h>
#include <string.h>
const int maxn = 100000 + 5;
int a, b;
int vis[maxn], res[maxn];
int main() {
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
while(scanf("%d%d", &a, &b) == 2) {
memset(vis, -1, sizeof(vis));
int c = a % b, cnt = 0;
c *= 10;
while(vis[c] == -1) {
res[cnt] = c / b;
vis[c] = cnt++;
c %= b;
c *= 10;
}
// repeating cycle start-position
int sta_pos = vis[c];
printf("%d/%d = %d.", a, b, a/b);
for(int i = 0; i < sta_pos; i++) {
printf("%d", res[i]);
}
printf("(");
if(cnt - sta_pos <= 50) {
for(int i = sta_pos; i < cnt; i++) {
printf("%d", res[i]);
}
} else {
for(int i = sta_pos; i < sta_pos+50; i++) {
printf("%d", res[i]);
}
printf("...");
}
printf(")\n");
printf(" %d = number of digits in repeating cycle\n\n", cnt - sta_pos);
}
return 0;
}
#include <stdio.h>
#include <string.h>
char a[100005], b[100005];
int main() {
while (~scanf("%s%s", a, b)) {
int star = 0, lenb = strlen(b), lena = strlen(a);
for (int i = 0; i < lenb; i ++) {
if (a[star] == b[i])
star ++;
if (star == lena) {
printf("Yes\n");
break;
}
}
if (star != lena)
printf("No\n");
}
return 0;
}
#include<stdio.h>
#include<algorithm>
using namespace std;
pair <int,int> box[6];//注意书写方式
int i;
int main(){
while(1){
for(i=0;i<6;i++){
if(scanf("%d%d",&box[i].first,&box[i].second)!=2) return 0;
if(box[i].first>box[i].second)
swap(box[i].first,box[i].second);
}
sort(box,box+6);//我试了一下,此处排序是按照先first递增,其次second递增排序
puts(box[0].first==box[1].first&&box[1].first==box[2].first&&box[2].first==box[3].first&&
box[0].second==box[1].second&&box[1].second==box[4].first&&box[4].first==box[5].first&&
box[2].second==box[3].second&&box[3].second==box[4].second&&box[4].second==box[5].second?
"POSSIBLE":"IMPOSSIBLE");
}
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
char a[105],b[105];
int i,j,l1,l2;
while(scanf("%s%s",a,b)!=EOF){
int lena=strlen(a);
int lenb=strlen(b);
for(i=0;i<lena;i++){ //以字符串a为基准,b滑动匹配
int flag=1;
for(j=0;j<lenb && (i+j)<lena;j++){ //依次对比
if((a[i+j]=='2') && (b[j]=='2')){ //不匹配,b往后滑,再依次匹配
flag=0;
break;
}
}
if(flag){
break;
}
}
l1=max(lena,lenb+i); //取(基准字符串a的长度)与(滑动字符串b的长度加滑动长度)中最大值,保证能够涵盖匹配后的字符串
for(i=0;i<lenb;i++){
int flag=1;
for(j=0;j<lena && (i+j)<lenb;j++){
if((b[i+j]=='2') && (a[j]=='2')){
flag=0;
break;
}
}
if(flag){
break;
}
}
l2=max(lenb,lena+i);
int l=min(l1,l2); //保证求出的是最短容器长度
printf("%d\n",l);
}
return 0;
}
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
using namespace std;
int main() {
double M[20][40];
long long E[20][40];
// 打表
for(int i = 0; i <= 9; ++i) for(int j = 1; j <= 30; ++j) {
double m = 1 - pow(2, -1 - i), e = pow(2, j) - 1;
double t = log10(m) + e * log10(2);
E[i][j] = t, M[i][j] = pow(10, t - E[i][j]);
}
// 输入并输出结果
string in;
while(cin >> in && in != "0e0") {
// 处理输入
for(string::iterator i = in.begin(); i != in.end(); ++i) if(*i == 'e') *i = ' ';
istringstream ss(in);
double A; int B;
ss >> A >> B;
while(A < 1) A *= 10, B -= 1;
// 在打好的表中寻找答案
for(int i = 0; i <= 9; ++i) for(int j = 1; j <= 30; ++j) {
if(B == E[i][j] && (fabs(A - M[i][j]) < 1e-4 || fabs(A / 10 - M[i][j]) < 1e-4)) {
cout << i << ' ' << j << endl;
break;
}
}
}
}