1 条题解
-
0
C :
#include<stdio.h> #include<string.h> char tw[4][15]={"bowl","knife","fork","chopsticks"}; int main() { int n,i,c; char s[15]; while(scanf("%d",&n)!=EOF) { c=0; while(n--) { scanf("%s",s); for(i=0;i<4;i++) if(!strcmp(s,tw[i])) { c++; if(c==1) printf("%s",s); else printf(" %s",s); break; } } printf("\n"); } return 0; }
C++ :
#include<stdio.h> #include<string.h> char tw[4][15]={"bowl","knife","fork","chopsticks"}; int main() { int n,i,c; char s[15]; while(scanf("%d",&n)!=EOF) { c=0; while(n--) { scanf("%s",s); for(i=0;i<4;i++) if(!strcmp(s,tw[i])) { c++; if(c==1) printf("%s",s); else printf(" %s",s); break; } } printf("\n"); } return 0; }
Pascal :
program p1046; var st,s:string; i,j,k,n:longint; begin while not eof do begin readln(st); k:=pos(' ',st); val(copy(st,1,k-1),n); delete(st,1,k); st:=st+' '; j:=0; for i:=1 to n do begin k:=pos(' ',st); s:=copy(st,1,k-1); if (s='bowl') or (s='knife') or (s='fork') or(s='chopsticks') then if j=0 then begin write(s); j:=j+1; end else write(' ',s); delete(st,1,k); end; writeln; end; end.
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); final String[] cooks = {"bowl", "knife", "fork", "chopsticks"}; while(in.hasNext()){ int n = in.nextInt(); String[] ss = new String[n]; StringBuffer sb = new StringBuffer(); for(String s:ss){ s = in.next(); for(String tem:cooks) if(s.equals(tem)) sb.append(" ").append(s); } System.out.println(sb.toString().substring(1)); } } }
Python :
import sys T = ['bowl','knife','fork','chopsticks'] for line in sys.stdin: data = line.split() B=map(lambda x:x if x in T else '',data) print (' '.join([i for i in B])).strip()
C# :
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string str; while ((str=Console.ReadLine())!=null) { string[] ans = str.Split(' '); string mtr = string.Empty; for (int i = 1; i < ans.Length; i++) { if (ans[i] == "bowl" || ans[i] == "fork" || ans[i] == "chopsticks" || ans[i] == "knife") { if (mtr == "") { mtr += ans[i]; } else mtr += " " + ans[i]; } } Console.WriteLine(mtr); } } } }
- 1
信息
- ID
- 6236
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者