1174: 零起点学算法81——求整数绝对值

1174: 零起点学算法81——求整数绝对值

Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld
Submitted: 742  Accepted: 511
[Submit][Status][Web Board]

Description

求一整数的绝对值。

Input

输入数据有多组,每组占一行,每行包含一个整数。

Output

对于每组输入数据,输出它的绝对值,要求每组数据输出一行。

Sample Input

 
123

Sample Output

123

HINT

 注意数值会比较大,建议用字符串处理

Source

 
 1 #include<stdio.h>
 2 #include<string.h>
 3 int main(){
 4     char a[10000];
 5     while(gets(a)!=NULL){
 6         int l;
 7         l=strlen(a);
 8         if(a[0]=='-'){
 9             for(int i=1;a[i];i++) a[i-1]=a[i];
10             a[l-1]='';  
11          }
12          puts(a);
13     } 
14     return 0;
15 }
原文地址:https://www.cnblogs.com/dddddd/p/6687234.html