本題要求編寫程序,從給定字符串中查找某指定的字符。
輸入格式:
輸入的第一行是一個待查找的字符。第二行是一個以回車結束的非空字符串(不超過80個字符)。
輸出格式:
如果找到,在一行內按照格式“index = 下標”輸出該字符在字符串中所對應的最大下標(下標從0開始);否則輸出"Not Found"。
輸入樣例1:
m
programming
輸出樣例1:
index = 7
輸入樣例2:
a
1234
輸出樣例2:
Not Found
#include<stdio.h> int main(void) { char ch; char string='0'; int i,j,sign; sign=-1,i=0; int a[80]; scanf("%c\n",&ch); while(string!='\n'){ scanf("%c",&string); a[i++]=string; } for(j=0;j<i;j++){ if(a[j]==ch) sign=j; } if(sign!=-1) printf("index = %d",sign); else printf("Not Found"); return 0; }