当前位置:网站首页>C language OJ gets PE, OJ of ACM introduction~
C language OJ gets PE, OJ of ACM introduction~
2022-07-05 19:55:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
So-called OJ, seeing the name of a thing one thinks of its function Online Judge, A user submitted program in Online Judge The execution under the system will be strictly restricted , Including runtime limits , Memory usage limit and security limit, etc . The result of user program execution will be Online Judge The system captures and saves , Then transfer it to a referee procedure . The referee program or compares the difference between the output data of the user program and the standard output sample , Or check whether the output data of the user program meets certain logical conditions . Finally, the system returns a status to the user : adopt (Accepted,AC)、 Wrong answer (Wrong Answer,WA)、 Overtime (Time Limit Exceed,TLE)、 Output limit exceeded (Output Limit Exceed,OLE)、 Super memory (Memory Limit Exceed,MLE)、 Runtime error (Runtime Error,RE)、 Format error (Presentation Error,PE)、 Or cannot compile (Compile Error,CE), And return the memory used by the program 、 Operation time and other information .
Maybe I'm not familiar with the definition after reading OJ, Recommend Hangzhou power ACM1000, We can consolidate our understanding of OJ Master the input and output of .
Hang Dian ACM Official website :http://acm.hdu.edu.cn/
Then next is about OJ The judgement of :
Starting to do OJ when , There will be a problem of input and output data ,OJ The input and output data in is different from the usual writing program . Why? Why would it be different , This involves how the evaluation system judges that the program you submit is correct . In fact, the evaluation system inputs the standard input of the program The output data is put in a text file , The program you submit will be compiled first , And then run , Read data from input file , Then lose the result Out to a text file , The evaluation system then compares the standard output file with the output file of the running result of the program you submitted , Thus judge Determine whether the program you submitted is correct . Since it is , To judge the correctness of the submitted program depends on the test data of the system , At this time, you can't It can only use a set of test data to judge the correctness of the program , There need to be many sets of test data , The evaluation system of international programming competition standard is PC2, It only supports one subject and one input data file 、 An output data file . So at this time, you have to put multiple groups of test data in one document In this case , The submitted program must get the results of multiple groups of input data in this file .
One 、 Input : 1、 Only one set of test data , This is the simplest . C The language code :
#include
int main()
{ int a,b;
scanf(“%d %d”,&a, &b);
printf(“%d\n”,a+b);
return0;
}
C++ The language code :
1 #include
2 usingnamespace std;
3 int main()
4 {
5 int a,b;
6 cin >> a >> b;
7 cout <
8 return0;
9 }
2、 Multiple sets of test data , Read until the end of the input file , You need to use while(scanf(“%d”,&n)!=EOF) or while(~scanf(“%d”,&n)) or while (cin>>n).
C The language code :
1 #include
2 int main()
3 {
4 int a,b;
5 while(scanf(“%d %d”,&a, &b) != EOF)
6 printf(“%d\n”,a+b);
7 return0;
8 }
explain :scanf The return value of the function is the number of variables read , Such as :scanf( “%d %d”, &a, &b ); If there is only one integer input , return The return value is 1, If there are two integer inputs , The return value is 2, If none of them , Then the return value is -1.EOF Is a predefined constant , etc.
On -1.
C++ The language code :
1 #include
2 usingnamespace std;
3 int main()
4 {
5 int a,b;
6 while(cin >> a >> b)
7 cout <
8 return0;
9 }
3、 At the beginning, enter a N, Next is N Group data . C The language code :
1 #include
2 int main()
3 {
4 int n,i;
5 int a,b;
6 scanf(“%d”,&n);
7 for(i=0;i
8 {
9 scanf(“%d%d”,&a,&b);
10 printf(“%d\n”,a+b);
11 }
12 return0;
13 }
perhaps
1 #include
2 int main()
3 {
4 int n, i;
5 int a, b;
6 scanf(“%d”, &n);
7 while (n–)
8 {
9 scanf(“%d%d”, &a, &b);
10 printf(“%d\n”, a + b);
11 }
12 return0;
13 }
C++ Code :
1 #include usingnamespace std;
2 int main()
3 {
4 int a, b, n;
5 cin >> n;
6 while (n–)
7 {
8 cout <
9 }
10 return0;
11 }
4、 Input does not indicate how many groups of data there are , But it ends with a special input . Such as 0 0 Represents the end of input . C The language code :
#include
int main()
{
int a,b;
while(scanf(“%d %d”,&a, &b) &&(a||b))
printf(“%d\n”,a+b);
}
C++ The language code :
1 #include
2 usingnamespace std;
3 int main()
4 {
5 int a ,b;
6 while(cin>>a>>b&&(a||b))
7 {
8 cout<
9 }
10 return0;
11 }
5、 There is also a combination of the first several . C The language code :
1 #include
2 int main()
3 {
4 int n,sum,a;
5 while(scanf(“%d”,&n) && n)
6 {
7 sum=0;
8 while(n–)
9 {
10 scanf(“%d”,&a);
11 sum+=a;
12 }
13 printf(“%d\n”,sum);
14 return 0;
15 }
C++ The language code :
1 #include
2 usingnamespace std;
3 int main()
4 {
5 int n,sum,a;
6 while(cin>>n&&n)
7 {
8 sum=0;
9 while(n–)
10 {
11 cin>>a;
12 sum+=a;
13 }
14 cout<
15 }
16 return0;
17 }
The input is a whole line of string ,C grammar :
char buf[20];
gets(buf);
If you use string buf; To preserve :
getline( cin , buf );
If you use char buf[ 255 ]; To preserve :
cin.getline( buf, 255 );
scanf(“ %s%s”,str1,str2), Separate multiple strings with one or more spaces ;
If you use gets function , Should be gets(str1); gets(str2); The strings are separated by carriage returns .
Usually , Accept short characters with scanf function , Accept long characters with gets function .
and getchar Function accepts only one character at a time , often c=getchar() Use it like this .
getline It's a function , It can accept the characters entered by the user , Until the specified number has been reached , Or the user enters a specific character . it
Function declaration form of ( The function prototype ) as follows :
istream& getline(char line[], int size, char endchar = ‘\n’);
Never mind its return type , To care about its three parameters
char line[]: It's an array of characters , The contents entered by the user will be stored in this array .
int size : A few characters at most ? Users over size All input will not be accepted .
char endchar : When user input endchar Specified characters , Automatic end . The default is carriage return .
Combine the last two parameters ,getline It can be easily realized : The user can input at most a specified number of characters , If exceeded , Then only specify the front of the number Characters are valid , If not more than , Then the user can enter to end the input .
char name[4];cin.getline(name,4,’\n’);
because endchar The default is already ‘\n’, So the last line can also be written :
cin.getline(name,4);
The last thing to say is ,C++ The input / output stream of is convenient to use , But the speed ratio C It's much slower . When the input and output volume is huge , use C++ It's likely to time out , Should use C Input and output of .
Two 、 Output :
Output has different format requirements , If you don't pay attention, it often appears “Presentation Error”, and PC2 Most of the time, I can't judge whether to lose Format error , It is simply judged as ”Wrong Answer”, So we must pay attention to the output format .
C The language code :
1 #include
2 int main()
3 // hold main Function defined as int type
4 {
5 int a,b;
6 while(scanf(“%d %d”,&a, &b) != EOF)
7 printf(“%d\n”,a+b);
8 return0;
9 }
Each output group of results can be wrapped .
2、 Group by group , There is a blank line behind each group .
C The language code :
1 #include
2 int main()
3 {
4 int a, b;
5 while (scanf(“%d%d”, &a, &b) != EOF)
6 printf(“%d\n\n”, a + b);
7 return0;
8 }
Output two line breaks after each group of results .
3、 Group by group , There is a blank line between each two groups , Pay attention to distinguish from the former .
1 #include
2 int main()
3 {
4 int n,m,sum,a;
5 int i;
6 scanf(“%d”,&n);
7 for (i =0; i
8 {
9 scanf(“%d”,&m);
10 sum =0;
11 while (m–)
12 {
13 scanf(“%d”,&a);
14 sum +=a;
15 }
16 printf(“%d\n”,sum);
17 if (i != n-1)
18 printf(“\n”);
19 }
20 return0;
21 }
Determine whether the last set of test data has been reached , If it is not the last set of test data, output one more line feed
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/150009.html Link to the original text :https://javaforall.cn
边栏推荐
- Necessary skills for interview in large factories, 2022android will not die, I will not fall
- Go language | 02 for loop and the use of common functions
- 通配符选择器
- 【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
- 股票开户哪里好?网上客户经理开户安全吗
- BZOJ 3747 POI2015 Kinoman 段树
- 通过POI追加数据到excel中小案例
- Relationship between floating elements and parent and brother boxes
- Parler de threadlocal insecurerandom
- C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
猜你喜欢
Jvmrandom cannot set seeds | problem tracing | source code tracing
安卓面试宝典,2022Android面试笔试总结
SecureRandom那些事|真伪随机数
Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
leetcode刷题:二叉树10(完全二叉树的节点个数)
Database logic processing function
秋招字节面试官问你还有什么问题?其实你已经踩雷了
Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
随机推荐
完爆面试官,一线互联网企业高级Android工程师面试题大全
Debezium series: PostgreSQL loads the correct last submission LSN from the offset
C#应用程序界面开发基础——窗体控制(5)——分组类控件
软件测试工程师是做什么的?待遇前景怎么样?
Elk distributed log analysis system deployment (Huawei cloud)
selenium 元素信息
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
Common operators and operator priority
[untitled]
司空见惯 - 英雄扫雷鼠
c语言oj得pe,ACM入门之OJ~
Let's talk about threadlocalinsecurerandom
Force buckle 729 My schedule I
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
MySql的root密码忘记该怎么找回
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
国信证券在网上开户安全吗?
Necessary skills for interview in large factories, 2022android will not die, I will not fall
Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array