您的位置:首页 > 编程语言 > C语言/C++

2017-2-9get

2017-02-09 21:52 183 查看

Linux

没贡献

C

竖式问题 输入数字集合s,找出所有abc*de(三位数乘以两位数)的算式,使得在完整的竖式中,所有的数字都属于这个数字集合s。

样例输入:

2375

样例输出:

<1>

..775

X..33

“—–”

.2325

2325.

“—–”

25575

分析:将abc,de,abc*d,abc*e,,abc*de连接起来保存在一个字符串buf中。遍历buf,在s中查找,如果没有查询到(buf有某个字符不在s中),则改变abc、de进行下一次遍历。

可能要用到sprintf用来将几个数字连接为一个字符串,strlen获得buf的实际长度,strchr进行字符串查找

代码如下:

#include <stdio.h>
#include <string.h>

int main(){
char s[20],buf[99];
scanf("%s",s);
for (int abc=111;abc<1000;abc++){
for (int de=11;de<100;de++){
int x = abc*(de%10), y= abc*(de/10), z=abc*de;
sprintf(buf,"%d%d%d%d%d",abc,de,x,y,z);
int ok=1;
for (int i=0; i<strlen(buf);i++){
if (strchr(s,buf[i])==NULL){
ok = 0;
}
}
if (ok){
printf("%5d\nX%4d\n-----%5d\n%4d\n-----%5d\n",abc,de,x,y,z);
}
}
}
return 0;
}


TeX中的引号

在TeX中,左双引号是“,右双引号是”,输入一片包含双引号的文章,把它转换为TeX格式。

样例输入:

“To be or not to be,” quoth the Bard, “that

is the question”.

样例输出:

To be or not to be,'' quoth the Bard,
that

is the question”.

分析:因为文章中可能有一个或多个空格,或者tab、回车,用scanf不方便输入。所以选用fgetc()或者getchar()。getchar返回的是一个int型,可以在输出的时候强转为char型:printf(“%c”,c)

fgets(stdin)== getchar()

代码如下,注释的为fgets()方法:

#include <stdio.h>

int main(){
int c,q=1;
FILE *fin;
// fin = fopen("data.in","rb");
// while ( (c=fgetc(fin)) != EOF){
while ( (c=getchar()) != EOF){
if (c == '"'){
printf("%s", q? "``" : "''");
q = !q;
}else {
printf("%c", c); // int 强转为 char
}
}
// fclose(fin);
return 0;
}


github

学习reflect包,里面两个重要的类型 Type和Value

mysql

insert into users(id) values(”) id为int型,一般会报错,但如果mode为非严格模式,不会报错
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言