1、开发一个程序,用户从键盘输入英文单词,程序要返回该单词对应的数值.规则是A/a的值是1, B/b的值是2, C/c的值是3,Z/z的值是26.如果用户输入的单词的和为100,那么就显示恭喜你成功找到了这个单词的信息。要求如下:
要求先给出求解思路
要求用到数组;
要写一个函数去返回单词对应的数值;
要求检查用户输入的内容为单词,不能是数字字符或其它字符,只能是大小写字母;
程序终止条件:用户选择停止程序或用户正确提交了值为100的单词,否则,程序将继续要求用户输入新单词。
2、搜索引擎接收到输入的关键词之后会返回结果列表,每条结果记录包含内容和匹配度两个信息。一般情况,检索结果的匹配度得分越高排在越靠前的位置,请编写程序按匹配度由高往低排序。结果匹配度得分样本如下表所示:
内容 匹配度
T1 0.77
T2 0.68
T3 0.99
T4 0.88
样本数据可以采用控制台输入的方式导入程序。排序后,输出结果如下:
内容 匹配度
T3 0.99
T4 0.88
T1 0.77
T2 0.68
要求采用结构体表示单条结果记录。
要求:
2.1 要求先给出求解思路
2.2 要求用到结构体数组或动态分配
题1、
我们可以使用while(1)去接收用户输入的数字,如果>=100则退出循环,如果没有,继续执行.
判断AZ:根据asiil码表,AZ为6590,az为97~122,则我们可以在函数中去判断有没有他们
有的话:
1)、大小字母:c%64
2)、小写字母:c%96
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int Input(char c)
{
int ret = 0;
if (c >= 65 && c <= 90)
{
ret += c % 64;
}
else if (c >= 97 && c <= 122)
{
ret += c % 96;
}
return ret;
}
int main()
{
printf("输入字母:");
int input_c = 0;
while (1)
{
char c = '\0';
c = _getch();
printf("%c", c);
input_c += Input(c);
if (input_c >= 100)
{
printf("恭喜,输入到了100\n");
break;
}
}
system("pause>0");
return 0;
}
题2、
```c
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int Input(char c)
{
int ret = 0;
if (c >= 65 && c <= 90)
{
ret += c % 64;
}
else if (c >= 97 && c <= 122)
{
ret += c % 96;
}
return ret;
}
int main()
{
printf("输入字母:");
int input_c = 0;
while (1)
{
char c = '\0';
c = _getch();
printf("%c", c);
input_c += Input(c);
if (input_c >= 100)
{
printf("恭喜,输入到了100\n");
break;
}
}
system("pause>0");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Result
{
char* information;
int about_this;
double persent;
};
struct Result* Search(char *str,char *input,int count)
{
struct Result *ret = malloc(sizeof(struct Result));
int r = strlen(input);
ret->about_this = 0;
ret->information = str;
for (int i = 0; i <= r; i++)
{
if (str[i] == input[i])
ret->about_this++;
}
return ret;
}
int main()
{
char* information[4] = { "Dev C++","C","Visual Studio CCC","You CAB" };
printf("输入要查找的内容:");
char str[1000] = { "\0" };
scanf_s("%s", str,1000);
struct Result t[4];
struct Result* r[4] = { &t };
r[0] = Search(information[0], str, 0);
r[1] = Search(information[1], str, 1);
r[2] = Search(information[2], str, 2);
r[3] = Search(information[3], str, 3);
struct Result *temp;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4-i; j++)
{
if (r[j] > r[j + 1])
{
temp = r[j];
r[j] = r[j] + 1;
r[j + 1] = temp;
}
}
}
double Persent[4] = { 0.99,0.88,0.77,0.68 };
for (int i = 0; i < 4; i++)
{
if (r[i]->about_this != 0)
{
r[i]->persent = Persent[i];
}
else
{
r[i]->persent = 0.00;
}
}
for (int i = 0; i < 4; i++)
{
printf("信息:%s ,匹配度:%lf", r[i]->persent);
}
system("pause>0");
return 0;
}
```
第一题
int fun(char *a)
{
int sum=0;
for (int i=0;i<strlen(a)-1;i++) //循环每一个字符
{
if(a[i]>64&&a[i]<91)
{
a[i]%=64;
sum+=a[i];
}
else if (a[i]>96&&a[i]<123)
{
a[i]%=96;
sum+=a[i];
}
else //上面两个条件判断是不是字母,当有一个不是字母返回main函数
{
printf("It's not all letters\n");
return 0;
}
}
return sum; //返回字符串的和
}
int main()
{
int sum;
while (1)
{
char a[100];
scanf("%s",a); //数组接收字符串
getchar();
sum=fun(a); //接收字符串的和
printf("%d\n",sum);
printf("please input again:");
if(sum==100) //当和为100,跳出循环
{
printf("succeed");
break;
}
}
}