提交记录 #456
提交时间:2024-12-06 17:27:17
语言:c
状态:Unaccepted
编译情况:编译成功
code.c: In function ‘main’:
code.c:81:9: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
81 | gets(word);
| ^~~~
| fgets
code.c:77:10: warning: unused variable ‘b’ [-Wunused-variable]
77 | char b=getchar();
| ^
/usr/bin/ld: /tmp/ccSz0ndI.o: in function `main':
code.c:(.text.startup+0x77): warning: the `gets' function is dangerous and should not be used.
固定测试点#1:
额外测试点#1:
H24【选做▪应用】编码
#include<stdio.h>
#include<string.h>
#include<ctype.h>
//int record[11]={0};
int is_word(char word[11]){
int i;
if (strlen(word)==0||strlen(word)>10){
return 0;
}
int check[26]={0};
for (i=0;i<strlen(word);i++){
if (!islower(word[i])||check[word[i]-'a']){
return 0;
}
if (i>0&&word[i]<=word[i-1]){
return 0;
}
}
return 1;
}
int comb(int n,int k){
int zi=1,mu=1;
int i,j;
if (k==0){
return 0;
}
for (i=n,j=1;j<=k;i--,j++){
zi*=i;
mu*=j;
}
return zi/mu;
}
int code(char word[11]){
int i,j;
int count=0;
if (strlen(word)==1){
return word[0]-'a'+1;
}
for (i=0;i<strlen(word);i++){
int pos=word[i]-'a';
for (j=0;j<pos;j++){
count+=comb(26-pos-1,strlen(word)-i-1);
}
}
count+=word[strlen(word)-1]-word[strlen(word)-2];
count++;
for (i=1;i<strlen(word);i++){
count+=comb(26,i);
}
// record[strlen(word)]=count;
return count;
}
//int cal(char word[11]){
// int N=strlen(word);
// int i;
// int count=0;
// char re_word[11]={'\0'};
// for (i=1;i<strlen(word);i++){
// if (record[i]!=0){
// count+=record[i];
// }
// else {
// int j;
// for (j=0;j<i;j++){
// re_word[j]='z'-j;
// }
// count+=code(re_word);
// }
// }
// count+=code(word);
//}
int main(){
int n;
scanf("%d",&n);
char b=getchar();
int i;
for (i=0;i<n;i++){
char word[11]={'\0'};
gets(word);
if (!is_word(word)){
printf("0\n");
return 0;
}
int result=code(word);
printf("%d\n",result);
}
return 0;
}