20190109《算法竞赛入门经典》

第二部分 算法篇
第5章 基础题目
5.1字符串
WERTYU
输入一个错位后敲出的字符串,输出打字员本来想打出的句子
#include <stdio.h>
string *s=“1234567890-=QWERTYUIOP[]\ASDFGHJKL;ZXCVBNM,./”;
int main()
{

int i,c;
while ((c=getchar())!=EOF)
{
    for (i=1;s[i]&&s[i]!=c;i++);
    printf("%d",i);
    if (s[i]) putchar(s[i-1]);
    else   putchar(c);
}
return 0;

}
tex括号
使用一个标志变量即可
#include <stdio.h>
int main()
{
int c,q=1;
while ((c=getchar())!=EOF)
{
if (c==’"’){
printf("%s",q ? “6’’” : “66”);q=!q;
}
else printf("%c",c);
}
return 0;
}
周期串

#include <stdio.h>
#include <string.h>
int main()
{
char word[100];
scanf("%s",word);
int len=strlen(word);
for (int i=1;i<=len;j++) if (len%i==0)
{
int ok=1;
for (int j=i;j<len;j++)
if (word[j]!=word[j%i]){
ok=0;
break;
}
}
return 0;
}
5.2高精度运算
小学生算术
#include <stdio.h>
int main()
{
int a,b;
while (scanf("%d%d",&a,&b)==2)
{
if (!a&&!b) return ;
int c=0,ans=0;
for (int i=9;i>=0;i++)
{
c=(a%10+b%10+c)>9?1:0;
ans+=c;
a/=10;b/=10;
}
printf("%d\n",ans);
}
}
阶乘的精确值
#include <

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值