三大语言实例 (python,C/C++,Java)
Python3.5语言实例:
#coding = utf-8 import sys def Sub_string(a,b): c=[0]*len(b) for i in range(len(a)): for j in range(len(b)): if str(a[i]).find(str(b[j]))!=-1: c[j] = c[j] + 1 for k in c: print(k) if __name__=='__main__': N=int(sys.stdin.readline().strip()) a=list() b=list() for i in range(N): a.append(input()) M = int(sys.stdin.readline().strip()) for i in range(M): b.append(input()) Sub_string(a, b)
python2.7实例:
#!/usr/bin/env python # coding=utf-8 # Python使用的是2.7,缩进可以使用tab、4个空格或2个空格,但是只能任选其中一种,不能多种混用 while 1: a=[] s = raw_input() # raw_input()里面不要有任何提示信息 if s != "": for x in s.split(): a.append(int(x)) print sum(a) else: break
C语言实例:
#include <stdio.h> int main() { int a, b; while(scanf("%d%d", &a, &b) != EOF) printf("%d\n", a + b); }
C++语言实例:
#include <iostream> using namespace std; int main() { int a, b; while(cin>> a >> b) cout << a + b << endl; return 0; }
Java语言实例:
//package main //注意不要添加包名称,否则会报错。 import java.io.*; import java.util.*; class Test { } public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int a, b; while(cin.hasNextInt()) { a = cin.nextInt(); b = cin.nextInt(); System.out.println(a + b); } } }