1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | **Lucky receipt--二維陣列版本--失敗版** #include <stdio.h> #include <stdlib.h> int main() { int n; // printf("How many test cases?"); scanf("%d",n); // prnitf("Please input %d 8 words account:"); char *ptr=new char [n][8]; //輸入數字組 for(int i=0;i<n;i++) { for(int j=0;j<8;j++) {scanf("%d",a[i][j]);} } //判別是否有 8 for(int i=0;i<n;i++) { for(int j=7;j>=0;j--) { if(a[i][j]=='8') printf("big"); else { if(j==7) printf("bang"); else break; } } } system ("pause"); return 0; } Edit **Lucky receipt--老師版** #include <iostream> using namespace std; int main() { char str[200]; int n; cin>>n; for(int c=0;c<n;c++){ cin>>str; // cout<<str<<endl; int len=strlen(str); int count=0; for(int i=len-1;i>=0;i--){ if(str[i]=='8'){ count++; cout<<"big"; }else{ break; } } if(count==0) cout<<"bang"; cout<<endl; // cout<<count<<endl; } system("pause"); return 0; } |
Direct link: https://paste.plurk.com/show/2530736