#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int t;
scanf("%d ",&t);
int ptr=1;
int k;
for(k=1;k<=t;k++)
{
char input[101]={0};
int count=0;
gets(input);
for(int i=0;i<strlen(input);i++)
{
switch(input[i])
{
case 'a':count++;break;
case 'b':count+=2;break;
case 'c':count+=3;break;
case 'd':count++;break;
case 'e':count+=2;break;
case 'f':count+=3;break;
case 'g':count++;break;
case 'h':count+=2;break;
case 'i':count+=3;break;
case 'j':count++;break;
case 'k':count+=2;break;
case 'l':count+=3;break;
case 'm':count++;break;
case 'n':count+=2;break;
case 'o':count+=3;break;
case 'p':count++;break;
case 'q':count+=2;break;
case 'r':count+=3;break;
case 's':count+=4;break;
case 't':count++;break;
case 'u':count+=2;break;
case 'v':count+=3;break;
case 'w':count++;break;
case 'x':count+=2;break;
case 'y':count+=3;break;
case 'z':count+=4;break;
case ' ':count++;break;
}
}
if(count!=0)
printf("Case #%d: %d\n",k,count);
}
return 0;
}
//以上是程式碼 不知道怎麼了QQ
#include
#include
#include
#include
int main()
{
int t;
scanf("%d ",&t);
int ptr=1;
int k;
for(k=1;k<=t;k++)
{
char input[101]={0};
int count=0;
gets(input);
for(int i=0;i<strlen(input);i++)
{
switch(input[i])
{
case 'a':count++;break;
case 'b':count+=2;break;
case 'c':count+=3;break;
case 'd':count++;break;
case 'e':count+=2;break;
case 'f':count+=3;break;
case 'g':count++;break;
case 'h':count+=2;break;
case 'i':count+=3;break;
case 'j':count++;break;
case 'k':count+=2;break;
case 'l':count+=3;break;
case 'm':count++;break;
case 'n':count+=2;break;
case 'o':count+=3;break;
case 'p':count++;break;
case 'q':count+=2;break;
case 'r':count+=3;break;
case 's':count+=4;break;
case 't':count++;break;
case 'u':count+=2;break;
case 'v':count+=3;break;
case 'w':count++;break;
case 'x':count+=2;break;
case 'y':count+=3;break;
case 'z':count+=4;break;
case ' ':count++;break;
}
}
if(count!=0)
printf("Case #%d: %d\n",k,count);
}
return 0;
}
//以上是程式碼 不知道怎麼了QQ
你好,我記得switch case 只能用在{整數}上面,這個應該不行
(PS 若有講錯請見諒,小妹我很菜....... XD
#include
#include
#include
#include
int main()
{
int t;
scanf("%d ",&t);
int ptr=1;
int k;
for(k=1;k<=t;k++)
{
char input[101]={0};
int count=0;
gets(input);
for(int i=0;i<strlen(input);i++)
{
switch(input[i])
{
case 'a':count++;break;
case 'b':count+=2;break;
case 'c':count+=3;break;
case 'd':count++;break;
case 'e':count+=2;break;
case 'f':count+=3;break;
case 'g':count++;break;
case 'h':count+=2;break;
case 'i':count+=3;break;
case 'j':count++;break;
case 'k':count+=2;break;
case 'l':count+=3;break;
case 'm':count++;break;
case 'n':count+=2;break;
case 'o':count+=3;break;
case 'p':count++;break;
case 'q':count+=2;break;
case 'r':count+=3;break;
case 's':count+=4;break;
case 't':count++;break;
case 'u':count+=2;break;
case 'v':count+=3;break;
case 'w':count++;break;
case 'x':count+=2;break;
case 'y':count+=3;break;
case 'z':count+=4;break;
case ' ':count++;break;
}
}
if(count!=0)
printf("Case #%d: %d\n",k,count);
}
return 0;
}
//以上是程式碼 不知道怎麼了QQ
你好,我記得switch case 只能用在{整數}上面,這個應該不行
(PS 若有講錯請見諒,小妹我很菜....... XD
其實char本身也可定義為整數(ASCII碼)
還有照理講switch case應該是可以用於所有的資料形式(除strack,STL容器.....(我本身不常用有錯請多包涵